Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[0.5.3] support image.binary from openmv.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhuanchen committed Dec 2, 2022
1 parent b3fa55f commit b5e3901
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maixpy3_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
git submodule update --init --recursive
- uses: actions/setup-python@v2
with:
python-version: 3.8.5
python-version: 3.8
- name: Install dependencies
run: |
sudo apt update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maixpy3_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
git submodule update --init --recursive
- uses: actions/setup-python@v2
with:
python-version: 3.8.5
python-version: 3.8
- name: Install dependencies
run: |
sudo apt update
Expand Down
59 changes: 58 additions & 1 deletion ext_modules/_maix_image/_maix_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ maix_image &maix_image::_resize(int dst_w, int dst_h, int func, int padding, std
new_w = dst_w, new_h = new_w * src_h / src_w; // new_h / src_h = new_w / src_w => new_h = new_w * src_h / src_w
top = (dst_h - new_h) / 2, bottom = dst_h - new_h - top;
}
else
else
{ // Division loses precision
new_h = dst_h, new_w = new_h * src_w / src_h;
left = (dst_w - new_w) / 2, right = dst_w - new_w - left;
Expand Down Expand Up @@ -923,6 +923,63 @@ maix_image &maix_image::_mean(const int ksize, bool threshold, int offset, bool
return *this;
}

maix_image &maix_image::_binary(std::vector<std::vector<int>> &thresholds_src, bool invert, bool zero, maix_image &mask)
{

if (NULL == this->_img)
{
py::print("[image] is empty !");
return *this;
}

image_t img_tmp = {}, *arg_img = &img_tmp;
arg_img->w = this->_img->width;
arg_img->h = this->_img->height;
arg_img->pixels = (uint8_t *)this->_img->data;
arg_img->pixfmt = PIXFORMAT_RGB888;

list_t thresholds;
list_init(&thresholds, sizeof(color_thresholds_list_lnk_data_t));
for (auto src : thresholds_src)
{
color_thresholds_list_lnk_data_t tmp_ct;
tmp_ct.LMin = src[0];
tmp_ct.LMax = src[1];
tmp_ct.AMin = src[2];
tmp_ct.AMax = src[3];
tmp_ct.BMin = src[4];
tmp_ct.BMax = src[5];
list_push_back(&thresholds, &tmp_ct);
}

image_t *mask_img = NULL;
if (NULL != mask._img) // check if mask is NULL
{
if (this->_img->width == mask._img->width && this->_img->height == mask._img->height) // check if mask has same size with image
{
mask_img = (image_t *)malloc(sizeof(image_t));
if (mask_img)
{
mask_img->w = mask._img->width;
mask_img->h = mask._img->height;
mask_img->pixels = (uint8_t *)mask._img->data;
mask_img->pixfmt = PIXFORMAT_RGB888;
}
}
else
printf("The size of mask is different with input image,use default mask!");
}

fb_alloc_mark();
imlib_binary(arg_img, arg_img, &thresholds, invert, zero, mask_img);
fb_alloc_free_till_mark();

if (mask_img != NULL)
free(mask_img), mask_img = NULL;

return *this;
}

py::list maix_image::_imlib_get_statistics(std::vector<int> roi_src, std::vector<std::vector<int>> &thresholds_src, bool invert, maix_image &other_src, int bins, int l_bins, int a_bins, int b_bins)
{

Expand Down
2 changes: 2 additions & 0 deletions ext_modules/_maix_image/include/maix_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class maix_image : virtual public any_image, public maix_vision, public maix_cus

maix_image &_mean(const int ksize, bool threshold, int offset, bool invert, maix_image &mask);

maix_image &_binary(std::vector<std::vector<int>> &thresholds_src, bool invert, bool zero, maix_image &mask);

maix_image &_opencv_Canny(double threshold1, double threshold2, int apertureSize, bool L2gradient);
};
#endif
1 change: 1 addition & 0 deletions ext_modules/_maix_image/py_maix_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ PYBIND11_MODULE(_maix_image, mo)
// .def("gamma_corr",&maix_image::_gamma_corr,py::arg("gamma")=1.0,py::arg("contrast")=1.0,py::arg("brightness")=0.0)
.def("lens_corr", &maix_image::_lens_corr, py::arg("strength") = 1.8, py::arg("zoom") = 1.0, py::arg("x_corr") = 0.0, py::arg("y_corr") = 0.0)
.def("mean", &maix_image::_mean, py::arg("ksize") = 1, py::arg("threshold") = 0, py::arg("offset") = 0, py::arg("invert") = 0, py::arg("mask") = maix_image())
.def("binary", &maix_image::_binary, py::arg("thresholds"), py::arg("invert") = 0, py::arg("zero") = 0, py::arg("mask") = maix_image())
.def("find_rects", &maix_image::_imlib_find_rects, py::arg("roi") = std::vector<int>{0, 0, 0, 0}, py::arg("threshold"), py::arg("is_xywh") = 0)
.def("find_lines", &maix_image::_imlib_find_lines, py::arg("roi") = std::vector<int>{0, 0, 0, 0}, py::arg("x_stride") = 2, py::arg("y_stride") = 1, py::arg("threshold") = 1000, py::arg("theta_margin") = 25, py::arg("rho_margin") = 25)
.def("find_circles", &maix_image::_imlib_find_circles, py::arg("roi") = std::vector<int>{0, 0, 0, 0}, py::arg("x_stride") = 2, py::arg("y_stride") = 1, py::arg("threshold") = 2000, py::arg("x_margin") = 10, py::arg("y_margin") = 10, py::arg("r_margin") = 10, py::arg("r_min") = 2, py::arg("r_max") = 0, py::arg("r_step") = 2)
Expand Down
2 changes: 1 addition & 1 deletion maix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version='0.5.2'
version='0.5.3'

__all__ = ['display', 'camera', 'image']

Expand Down

0 comments on commit b5e3901

Please sign in to comment.