From c6b5c419a9c547f1f42c686020eb0e4cdb3f93cf Mon Sep 17 00:00:00 2001 From: junhuanchen Date: Fri, 24 Feb 2023 14:46:54 +0800 Subject: [PATCH] [0.5.4] fix freetype & r329 nn & fix rgba && remove orb. --- docs/develop.md | 2 +- envs/linux_desktop.py | 2 +- envs/maix_r329.py | 9 +++++---- envs/maix_v83x.py | 17 ++++++++++------- ext_modules/_maix_image/_maix_image.cpp | 12 ++++++------ .../_maix_image/include/costom_imlib_config.h | 2 +- ext_modules/_maix_image/include/cv_orb.hpp | 2 +- ext_modules/_maix_image/include/maix_image.h | 4 ++-- ext_modules/_maix_image/py_maix_image.cpp | 11 ++++++----- ext_modules/_maix_vivo/_maix_vivo.cpp | 9 +++++---- ext_modules/libmaix | 2 +- maix/__init__.py | 2 +- maix/camera.py | 2 +- maix/display.py | 9 +++++++-- 14 files changed, 48 insertions(+), 37 deletions(-) diff --git a/docs/develop.md b/docs/develop.md index 11d68b3..55ad8ad 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -81,7 +81,7 @@ your v83x - python3.8 setup.py bdist_wheel maix_v83x -- rm dist/* && python3.8 setup.py clean --all bdist_wheel maix_v83x && adb shell 'rm /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl' && adb push ./dist/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl /root/ && adb shell "pip install /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl --upgrade" +- rm -rf dist/* && python3.8 setup.py clean --all bdist_wheel maix_v83x && adb shell 'rm /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl' && adb push ./dist/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl /root/ && adb shell "pip install /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl --upgrade" - adb shell 'rm /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl' && adb push ./dist/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl /root/ && adb shell "pip install /root/maixpy3-0.5.*-cp38-cp38-linux_armv7l.whl --upgrade" diff --git a/envs/linux_desktop.py b/envs/linux_desktop.py index e4e8e03..fc2d238 100644 --- a/envs/linux_desktop.py +++ b/envs/linux_desktop.py @@ -117,7 +117,7 @@ get_srcs('ext_modules/libmaix/components/libmaix/lib/arch/desktop/libmaix_disp') + get_srcs('ext_modules/_maix_display'), libraries=[ - "opencv_videoio", "opencv_highgui", "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype" + "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype" ], library_dirs=[ "/usr/lib/", diff --git a/envs/maix_r329.py b/envs/maix_r329.py index 3ea0e47..a93282f 100644 --- a/envs/maix_r329.py +++ b/envs/maix_r329.py @@ -41,7 +41,9 @@ get_srcs('ext_modules/libmaix/components/maix_cv_image/src') + get_srcs('ext_modules/libmaix/components/third_party/imlib/src'), libraries=[ - "maix_image","maix_disp", "opencv_videoio", "opencv_highgui", "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype", "opencv_flann", "opencv_features2d", "opencv_calib3d" + "maix_image","maix_disp", + "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype" + # "opencv_videoio", "opencv_highgui", "opencv_flann", "opencv_features2d", "opencv_calib3d" ], library_dirs=["./ext_modules/libmaix/components/libmaix/lib/arch/r329/opencv4", ext_so, @@ -88,11 +90,10 @@ ], ) -max_nn_srcs = get_srcs('ext_modules/_maix_nn_mdsc/src') +max_nn_srcs = get_srcs('ext_modules/_maix_nn_mud/src') max_nn_srcs.extend(get_srcs('ext_modules/libmaix/components/libmaix/src')) max_nn_srcs.remove("ext_modules/libmaix/components/libmaix/src/libmaix.c") -_maix_nn_module = Extension('_maix_nn', - include_dirs=['ext_modules/_maix_nn_mdsc/include', 'ext_modules/libmaix/components/libmaix/include'], +_maix_nn_module = Extension('_maix_nn', include_dirs=['ext_modules/_maix_nn_mud/include', 'ext_modules/libmaix/components/libmaix/include'], sources=max_nn_srcs, libraries=[ "maix_utils", "maix_cam", "maix_nn", "maix_nn_app" diff --git a/envs/maix_v83x.py b/envs/maix_v83x.py index 44ad80a..fa31574 100644 --- a/envs/maix_v83x.py +++ b/envs/maix_v83x.py @@ -30,6 +30,7 @@ library_dirs=[ ext_so, ], extra_link_args=[ "-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"], + extra_compile_args=['-march=armv7-a', '-mfloat-abi=hard', '-mfpu=neon','-std=c++11', '-std=gnu++11' ], # define_macros=[('V831Camera', None)], ) @@ -112,7 +113,7 @@ "maix_disp", ], library_dirs=["/lib", "/usr/lib", ext_so, ], - # extra_compile_args=['-DV83xDisplay'], + extra_compile_args=[], extra_link_args=["-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"] ) @@ -152,6 +153,7 @@ "maix_utils", "maix_nn", "maix_cam", ], library_dirs=[ ext_so, ], + extra_compile_args=['-march=armv7-a', '-mfloat-abi=hard', '-mfpu=neon', ], # extra_link_args = [ "-Wl,-z,origin", "-Wl,-rpath='$ORIGIN/maix'" ] extra_link_args=["-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"] ) @@ -166,7 +168,7 @@ "maix_nn", ], library_dirs=[ ext_so, ], - # extra_compile_args=['-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], + extra_compile_args=['-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], extra_link_args=["-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"] ) @@ -180,7 +182,7 @@ "maix_nn", ], library_dirs=[ ext_so, ], - # extra_compile_args=['-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], + extra_compile_args=['-march=armv7-a', '-mfloat-abi=hard', '-mfpu=neon','-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], extra_link_args=["-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"] ) @@ -194,7 +196,7 @@ "maix_nn", ], library_dirs=[ ext_so, ], - # extra_compile_args=['-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], + extra_compile_args=['-march=armv7-a', '-mfloat-abi=hard', '-mfpu=neon','-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831'], extra_link_args=["-Wl,-rpath=/usr/lib/python3.8/site-packages/maix"] ) @@ -239,7 +241,8 @@ get_srcs('ext_modules/libmaix/components/third_party/imlib/src'), libraries=[ "maix_utils", "maix_cam", "maix_image", - "opencv_videoio", "opencv_highgui", "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype", "opencv_flann", "opencv_features2d", "opencv_calib3d" + "opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_freetype" + # "opencv_videoio", "opencv_highgui", "opencv_flann", "opencv_features2d", "opencv_calib3d" ], library_dirs=[ ext_so, @@ -249,7 +252,7 @@ "-Wl,-rpath=/usr/lib/python3.8/site-packages/maix", "-Wl,-rpath=/usr/lib/python3.8/site-packages" ], - extra_compile_args=['-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831', '-DIMLIB_CONFIG_H_FILE="costom_imlib_config.h"' ], + extra_compile_args=['-march=armv7-a', '-mfloat-abi=hard', '-mfpu=neon','-std=c++11', '-std=gnu++11', '-DCONFIG_ARCH_V831', '-DIMLIB_CONFIG_H_FILE="costom_imlib_config.h"' ], ) _maix_modules = [ @@ -259,7 +262,7 @@ _maix_image_module, # _maix_camera_module, _maix_speech_module, - _maix_display_module, + # _maix_display_module, _maix_nn_module, _maix_nn_decode_retinaface_module, _maix_nn_decode_license_plate_location_module, diff --git a/ext_modules/_maix_image/_maix_image.cpp b/ext_modules/_maix_image/_maix_image.cpp index efcf278..c3017cb 100644 --- a/ext_modules/_maix_image/_maix_image.cpp +++ b/ext_modules/_maix_image/_maix_image.cpp @@ -154,7 +154,7 @@ maix_image &maix_image::_new(std::vector size, std::vector color, std: this->_img = libmaix_image_create_patch(this->_img, size[0], size[1], any_cast(this->py_to_pram[this->get_to(this->_maix_image_type)][0]), LIBMAIX_IMAGE_LAYOUT_HWC, NULL, true); if (this->_img) { - libmaix_cv_image_draw_rectangle(this->_img, 0, 0, size[0], size[1], MaixColor(color[0], color[1], color[2]), -1); + libmaix_cv_image_draw_rectangle(this->_img, 0, 0, size[0], size[1], MaixColorBGRA(color[0], color[1], color[2], color[3]), -1); } else { @@ -555,7 +555,7 @@ maix_image &maix_image::_draw_line(int x1, int y1, int x2, int y2, std::vector_img, x1, y1, x2, y2, MaixColor(color[0], color[1], color[2]), thickness); + libmaix_cv_image_draw_line(this->_img, x1, y1, x2, y2, MaixColorBGRA(color[0], color[1], color[2], color[3]), thickness); return *this; } @@ -584,7 +584,7 @@ maix_image &maix_image::_draw_rectangle(int x1_x, int y1_y, int x2_w, int y2_h, } if (is_xywh) x2_w = x1_x + x2_w, y2_h = y1_y + y2_h; - libmaix_cv_image_draw_rectangle(this->_img, x1_x, y1_y, x2_w, y2_h, MaixColor(color[0], color[1], color[2]), thickness); + libmaix_cv_image_draw_rectangle(this->_img, x1_x, y1_y, x2_w, y2_h, MaixColorBGRA(color[0], color[1], color[2], color[3]), thickness); return *this; } @@ -595,7 +595,7 @@ maix_image &maix_image::_draw_circle(int x, int y, int r, std::vector color py::print("[image] is empty !"); return *this; } - libmaix_cv_image_draw_circle(this->_img, x, y, r, MaixColor(color[0], color[1], color[2]), thickness); + libmaix_cv_image_draw_circle(this->_img, x, y, r, MaixColorBGRA(color[0], color[1], color[2], color[3]), thickness); return *this; } @@ -606,7 +606,7 @@ maix_image &maix_image::_draw_ellipse(int cx, int cy, int rx, int ry, double ang py::print("[image] is empty !"); return *this; } - libmaix_cv_image_draw_ellipse(this->_img, cx, cy, rx, ry, angle, startAngle, endAngle, MaixColor(color[0], color[1], color[2]), thickness); + libmaix_cv_image_draw_ellipse(this->_img, cx, cy, rx, ry, angle, startAngle, endAngle, MaixColorBGRA(color[0], color[1], color[2], color[3]), thickness); return *this; } @@ -617,7 +617,7 @@ maix_image &maix_image::_draw_string(int x, int y, std::string str, double scale py::print("[image] is empty !"); return *this; } - libmaix_cv_image_draw_string(this->_img, x, y, str.c_str(), scale, MaixColor(color[0], color[1], color[2]), thickness); + libmaix_cv_image_draw_string(this->_img, x, y, str.c_str(), scale, MaixColorBGRA(color[0], color[1], color[2], color[3]), thickness); return *this; } diff --git a/ext_modules/_maix_image/include/costom_imlib_config.h b/ext_modules/_maix_image/include/costom_imlib_config.h index 1efddf6..893ca43 100644 --- a/ext_modules/_maix_image/include/costom_imlib_config.h +++ b/ext_modules/_maix_image/include/costom_imlib_config.h @@ -162,7 +162,7 @@ extern "C" // FB Heap Block Size #define OMV_UMM_BLOCK_SIZE 256 -#define OMV_FB_ALLOC_SIZE (4 * 1024 * 1024) // minimum fb alloc size +#define OMV_FB_ALLOC_SIZE (2 * 1024 * 1024) // minimum fb alloc size // Enable STM32 DMA2D // #define IMLIB_ENABLE_DMA2D diff --git a/ext_modules/_maix_image/include/cv_orb.hpp b/ext_modules/_maix_image/include/cv_orb.hpp index 5064223..bae014a 100644 --- a/ext_modules/_maix_image/include/cv_orb.hpp +++ b/ext_modules/_maix_image/include/cv_orb.hpp @@ -1,5 +1,5 @@ #ifndef cv_orb_hpp -#define cv_orb_hpp +// #define cv_orb_hpp #include "maix_image.h" diff --git a/ext_modules/_maix_image/include/maix_image.h b/ext_modules/_maix_image/include/maix_image.h index d536c7e..983222a 100644 --- a/ext_modules/_maix_image/include/maix_image.h +++ b/ext_modules/_maix_image/include/maix_image.h @@ -25,8 +25,8 @@ #include "libmaix_cv_image.h" #include "libmaix_disp.h" -#define enable_PIL -#define enable_numpy +// #define enable_PIL +// #define enable_numpy namespace py = pybind11; typedef enum diff --git a/ext_modules/_maix_image/py_maix_image.cpp b/ext_modules/_maix_image/py_maix_image.cpp index 8350568..e36cda1 100644 --- a/ext_modules/_maix_image/py_maix_image.cpp +++ b/ext_modules/_maix_image/py_maix_image.cpp @@ -1,6 +1,6 @@ #include "maix_image.h" -#include "cv_orb.hpp" +// #include "cv_orb.hpp" void _load_freetype(std::string path, int fontHeight) { @@ -155,8 +155,9 @@ PYBIND11_MODULE(_maix_image, mo) .def("find_template", &maix_image::_imlib_find_template, py::arg("template") = maix_image(), py::arg("thresh") = 0.5, py::arg("roi") = std::vector{0, 0, 0, 0}, py::arg("step") = 2, py::arg("search") = 1) .def("find_barcodes", &maix_image::_imlib_find_barcodes, py::arg("roi") = std::vector{0, 0, 0, 0}); // module end - pybind11::class_(mo, "orb") - .def(pybind11::init(), - py::arg("nfeatures") = 500, py::arg("scaleFactor") = 1.2f, py::arg("nlevels") = 8, py::arg("edgeThreshold") = 31, py::arg("firstLevel") = 0, py::arg("WTA_K") = 2, py::arg("scoreType") = 0, py::arg("patchSize") = 31, py::arg("fastThreshold") = 20) - .def("match", &cv_orb::match, pybind11::arg("src"), pybind11::arg("dst"), pybind11::arg("limit") = 30, pybind11::arg("min") = 0.0f, pybind11::arg("max") = 100.f, pybind11::arg("crossCheck") = false, pybind11::arg("dump") = 0); + // pybind11::class_(mo, "orb") + // .def(pybind11::init(), + // py::arg("nfeatures") = 500, py::arg("scaleFactor") = 1.2f, py::arg("nlevels") = 8, py::arg("edgeThreshold") = 31, py::arg("firstLevel") = 0, py::arg("WTA_K") = 2, py::arg("scoreType") = 0, py::arg("patchSize") = 31, py::arg("fastThreshold") = 20) + // .def("match", &cv_orb::match, pybind11::arg("src"), pybind11::arg("dst"), pybind11::arg("limit") = 30, pybind11::arg("min") = 0.0f, pybind11::arg("max") = 100.f, pybind11::arg("crossCheck") = false, pybind11::arg("dump") = 0); + } diff --git a/ext_modules/_maix_vivo/_maix_vivo.cpp b/ext_modules/_maix_vivo/_maix_vivo.cpp index 2d4676a..ea986e4 100644 --- a/ext_modules/_maix_vivo/_maix_vivo.cpp +++ b/ext_modules/_maix_vivo/_maix_vivo.cpp @@ -177,10 +177,11 @@ class _v83x_vivo uint32_t *argb = (uint32_t *)ui->buf, *abgr = (uint32_t *)value.c_str(); for (int i = 0, sum = frame_size; i != sum; i++) { - argb[i] = (abgr[i] & 0xFF000000) | // ______AA - ((abgr[i] & 0x00FF0000) >> 16) | // BB______ - (abgr[i] & 0x0000FF00) | // __GG____ - ((abgr[i] & 0x000000FF) << 16); // ____RR__ + argb[i] = __builtin_bswap32(argb[i]); + // argb[i] = (abgr[i] & 0xFF000000) | // ______AA + // ((abgr[i] & 0x00FF0000) >> 16) | // BB______ + // (abgr[i] & 0x0000FF00) | // __GG____ + // ((abgr[i] & 0x000000FF) << 16); // ____RR__ } } else if (frame_size * 3 == value.length()) diff --git a/ext_modules/libmaix b/ext_modules/libmaix index 1171580..9b90bb8 160000 --- a/ext_modules/libmaix +++ b/ext_modules/libmaix @@ -1 +1 @@ -Subproject commit 11715802f8d4da6736c7cb06e965b3773b9b3d60 +Subproject commit 9b90bb84fbfabd032e12451c333b0e21f8d6e57d diff --git a/maix/__init__.py b/maix/__init__.py index bfb5651..0fd4562 100644 --- a/maix/__init__.py +++ b/maix/__init__.py @@ -1,5 +1,5 @@ -version='0.5.3' +version='0.5.4' __all__ = ['display', 'camera', 'image'] diff --git a/maix/camera.py b/maix/camera.py index 68e87f3..97974a4 100644 --- a/maix/camera.py +++ b/maix/camera.py @@ -44,7 +44,7 @@ def close(self): try: try: # use mpp vivo on v831 - from maix import display, image + from maix import display from _maix_vivo import _v83x_vivo class V831VivoMaixVideo(MaixVideo): def __init__(self, source="allwinner mpp"): diff --git a/maix/display.py b/maix/display.py index 6569f39..4b945c3 100644 --- a/maix/display.py +++ b/maix/display.py @@ -16,9 +16,14 @@ def __draw__(img): global __show__, _width, _height if isinstance(img, bytes): __show__.draw(img, _width, _height) - from maix import camera except ModuleNotFoundError as e: - pass + # v83x remove _maix_display and dts get lcd size + import os + os.system("cat /sys/firmware/devicetree/base/soc@03000000/board/lcd > /tmp/lcd") + with open("/tmp/lcd", "r") as f: + lcd = f.read().strip() + if lcd.find("240,320") != -1: + config(size=(240, 320)) except Exception as e: pass