From 942d6533e63b1029e3fb179fe9cee6c589d9b496 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Mon, 15 Apr 2024 21:30:49 +0800 Subject: [PATCH] * support for maixpy-v1 --- examples/maixpy_v1/image/add_sub_mul_div.py | 37 + examples/maixpy_v1/image/bilateral.py | 15 + examples/maixpy_v1/image/binary.py | 12 + examples/maixpy_v1/image/bit_operation.py | 51 + examples/maixpy_v1/image/blend.py | 15 + examples/maixpy_v1/image/difference.py | 16 + examples/maixpy_v1/image/draw.py | 22 + examples/maixpy_v1/image/erode.py | 45 + examples/maixpy_v1/image/find_barcodes.py | 44 + examples/maixpy_v1/image/find_blobs.py | 165 +++ examples/maixpy_v1/image/find_circles.py | 20 + examples/maixpy_v1/image/find_edges.py | 20 + .../maixpy_v1/image/find_line_segments.py | 26 + examples/maixpy_v1/image/find_lines.py | 26 + examples/maixpy_v1/image/find_qrcodes.py | 52 + examples/maixpy_v1/image/find_rects.py | 28 + examples/maixpy_v1/image/flood_fill.py | 12 + examples/maixpy_v1/image/gaussian.py | 15 + examples/maixpy_v1/image/get_histogram.py | 33 + examples/maixpy_v1/image/get_regression.py | 28 + examples/maixpy_v1/image/get_statistics.py | 27 + examples/maixpy_v1/image/histeq.py | 14 + examples/maixpy_v1/image/invert.py | 12 + examples/maixpy_v1/image/invert_format.py | 22 + examples/maixpy_v1/image/laplacian.py | 15 + examples/maixpy_v1/image/linpolar_logpolar.py | 21 + examples/maixpy_v1/image/load_image.py | 12 + examples/maixpy_v1/image/mean.py | 14 + examples/maixpy_v1/image/midpoint.py | 14 + examples/maixpy_v1/image/min_max.py | 23 + examples/maixpy_v1/image/mode.py | 15 + examples/maixpy_v1/image/morph.py | 15 + examples/maixpy_v1/image/negate.py | 15 + examples/maixpy_v1/image/pool.py | 18 + examples/maixpy_v1/image/replace.py | 30 + examples/maixpy_v1/image/set_pixel.py | 18 + examples/maixpy_v1/{test_lcd.py => lcd.py} | 2 + .../maixpy_v1/{test_sensor.py => sensor.py} | 6 +- examples/maixpy_v1/test_image.py | 18 - maix/v1/image.py | 1070 ++++++++--------- maix/v1/lcd.py | 7 +- maix/v1/sensor.py | 14 +- 42 files changed, 1474 insertions(+), 610 deletions(-) create mode 100644 examples/maixpy_v1/image/add_sub_mul_div.py create mode 100644 examples/maixpy_v1/image/bilateral.py create mode 100644 examples/maixpy_v1/image/binary.py create mode 100644 examples/maixpy_v1/image/bit_operation.py create mode 100644 examples/maixpy_v1/image/blend.py create mode 100644 examples/maixpy_v1/image/difference.py create mode 100644 examples/maixpy_v1/image/draw.py create mode 100644 examples/maixpy_v1/image/erode.py create mode 100644 examples/maixpy_v1/image/find_barcodes.py create mode 100644 examples/maixpy_v1/image/find_blobs.py create mode 100644 examples/maixpy_v1/image/find_circles.py create mode 100644 examples/maixpy_v1/image/find_edges.py create mode 100644 examples/maixpy_v1/image/find_line_segments.py create mode 100644 examples/maixpy_v1/image/find_lines.py create mode 100644 examples/maixpy_v1/image/find_qrcodes.py create mode 100644 examples/maixpy_v1/image/find_rects.py create mode 100644 examples/maixpy_v1/image/flood_fill.py create mode 100644 examples/maixpy_v1/image/gaussian.py create mode 100644 examples/maixpy_v1/image/get_histogram.py create mode 100644 examples/maixpy_v1/image/get_regression.py create mode 100644 examples/maixpy_v1/image/get_statistics.py create mode 100644 examples/maixpy_v1/image/histeq.py create mode 100644 examples/maixpy_v1/image/invert.py create mode 100644 examples/maixpy_v1/image/invert_format.py create mode 100644 examples/maixpy_v1/image/laplacian.py create mode 100644 examples/maixpy_v1/image/linpolar_logpolar.py create mode 100644 examples/maixpy_v1/image/load_image.py create mode 100644 examples/maixpy_v1/image/mean.py create mode 100644 examples/maixpy_v1/image/midpoint.py create mode 100644 examples/maixpy_v1/image/min_max.py create mode 100644 examples/maixpy_v1/image/mode.py create mode 100644 examples/maixpy_v1/image/morph.py create mode 100644 examples/maixpy_v1/image/negate.py create mode 100644 examples/maixpy_v1/image/pool.py create mode 100644 examples/maixpy_v1/image/replace.py create mode 100644 examples/maixpy_v1/image/set_pixel.py rename examples/maixpy_v1/{test_lcd.py => lcd.py} (94%) rename examples/maixpy_v1/{test_sensor.py => sensor.py} (75%) delete mode 100644 examples/maixpy_v1/test_image.py diff --git a/examples/maixpy_v1/image/add_sub_mul_div.py b/examples/maixpy_v1/image/add_sub_mul_div.py new file mode 100644 index 0000000..c14095d --- /dev/null +++ b/examples/maixpy_v1/image/add_sub_mul_div.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# add +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.add(img2) +lcd.display(img) +time.sleep(1) + +# sub +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.sub(img2) +lcd.display(img) +time.sleep(1) + +# mul +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.mul(img2) +lcd.display(img) +time.sleep(1) + +# div +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.div(img2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/bilateral.py b/examples/maixpy_v1/image/bilateral.py new file mode 100644 index 0000000..6a1992d --- /dev/null +++ b/examples/maixpy_v1/image/bilateral.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +size = 1 +kernel = [-1, -2, -1, -2, 6, -2, -1, -2, -1] + +lcd.init() +img = image.Image("test.jpg") +img.bilateral(2, color_sigma = 0.1, space_sigma = 1) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/binary.py b/examples/maixpy_v1/image/binary.py new file mode 100644 index 0000000..63155a4 --- /dev/null +++ b/examples/maixpy_v1/image/binary.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() +img = image.Image("test.jpg") +img.invert() +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/bit_operation.py b/examples/maixpy_v1/image/bit_operation.py new file mode 100644 index 0000000..715ae84 --- /dev/null +++ b/examples/maixpy_v1/image/bit_operation.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# b_and +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_and(img2) +lcd.display(img) +time.sleep(1) + +# b_nand +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_nand(img2) +lcd.display(img) +time.sleep(1) + +# b_or +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_or(img2) +lcd.display(img) +time.sleep(1) + +# b_nor +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_nor(img2) +lcd.display(img) +time.sleep(1) + +# b_xor +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_xor(img2) +lcd.display(img) +time.sleep(1) + +# b_xnor +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.b_xnor(img2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/blend.py b/examples/maixpy_v1/image/blend.py new file mode 100644 index 0000000..beafebf --- /dev/null +++ b/examples/maixpy_v1/image/blend.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.blend(img2, alpha=128) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/difference.py b/examples/maixpy_v1/image/difference.py new file mode 100644 index 0000000..eca801d --- /dev/null +++ b/examples/maixpy_v1/image/difference.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# difference +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.difference(img2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/draw.py b/examples/maixpy_v1/image/draw.py new file mode 100644 index 0000000..1cef432 --- /dev/null +++ b/examples/maixpy_v1/image/draw.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() +img = image.Image(width = lcd.width(), height = lcd.height()) +img.clear() +img.draw_line(0, 0, 50, 50, (255,0,0), 3) +img.draw_rectangle(60, 0, 50, 50, (0,255,0), 3, True) +img.draw_ellipse(200, 50, 50, 50, 50, (0,0,255), 3, True) +img.draw_string(0, 100, "Hello world", (0,255,0)) +img.draw_cross(0, 200, (255,0,0)) +img.draw_arrow(100, 200, 100, 250, (0,255,0)) +new_img=image.Image("test.jpg") +img.draw_image(new_img.mean_pool(4, 4), 150, 200) +img.draw_keypoints((250, 200, 210, 200), (0,0,255)) +img.draw_circle(300, 200, 50, (0,255,0)) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/erode.py b/examples/maixpy_v1/image/erode.py new file mode 100644 index 0000000..1181f0f --- /dev/null +++ b/examples/maixpy_v1/image/erode.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# erode +img = image.Image("test.jpg") +img.erode(2, -1) +lcd.display(img) +time.sleep(1) + +# dilate +img = image.Image("test.jpg") +img.dilate(2, 0) +lcd.display(img) +time.sleep(1) + +# open +img = image.Image("test.jpg") +img.open(2, 0) +lcd.display(img) +time.sleep(1) + +# close +img = image.Image("test.jpg") +img.close(2, 0) +lcd.display(img) +time.sleep(1) + +# top_hat +img = image.Image("test.jpg") +img.top_hat(2, 0) +lcd.display(img) +time.sleep(1) + +# black_hat +img = image.Image("test.jpg") +img.black_hat(2, 0) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/find_barcodes.py b/examples/maixpy_v1/image/find_barcodes.py new file mode 100644 index 0000000..e991d88 --- /dev/null +++ b/examples/maixpy_v1/image/find_barcodes.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.VGA) +sensor.run(1) + +roi = [160, 120, 320, 240] + +while True: + img = sensor.snapshot() + + barcodes = img.find_barcodes(roi) + for a in barcodes: + # corners + corners = a.corners() + for i in range(4): + img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], (255,0,0), 2) + + # rect + rect = a.rect() + img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,0,255), 2) + img.draw_string(rect[0] + 5, rect[1] + 5, "rect", (0,0,255)) + + # payload + img.draw_string(a.x() + a.w() + 5, rect[1] + 20, "payload: " + a.payload(), (255,0,0)) + + # type + img.draw_string(a.x() + a.w() + 5, rect[1] + 35, "type: " + str(a.type()), (255,0,0)) + + # rotation + img.draw_string(a.x(), a.y() + 15, "rot: " + str(a.rotation()), (255,0,0)) + + # quality + img.draw_string(a.x(), a.y() + 30, "quality: " + str(a.quality()), (255,0,0)) + + img.draw_rectangle(roi[0], roi[1], roi[2], roi[3], (0,255,0)) + img.draw_string(roi[0] + 5, roi[1] + 5, "ROI", (0,255,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_blobs.py b/examples/maixpy_v1/image/find_blobs.py new file mode 100644 index 0000000..b770259 --- /dev/null +++ b/examples/maixpy_v1/image/find_blobs.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +thresholds = [[0, 80, 40, 80, 10, 80]] # red + +while True: + img = sensor.snapshot() + + blobs = img.find_blobs(thresholds) + for a in blobs: + # draw rect + rect = a.rect() + img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,255,0)) + + # corners + corners = a.corners() + for i in range(4): + img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], (255,0,0)) + img.draw_string(corners[0][0] + 5, corners[0][1] + 5, "corners area: " + str(a.area()), (255,0,0)) + + # mini_corners + mini_corners = a.mini_corners() + for i in range(4): + img.draw_line(mini_corners[i][0], mini_corners[i][1], mini_corners[(i + 1) % 4][0], mini_corners[(i + 1) % 4][1], (0,255,0)) + img.draw_string(mini_corners[0][0] + 5, mini_corners[0][1] + 5, "mini_corners", (0,255,0)) + + # rect + rect = a.rect() + img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,0,255)) + img.draw_string(rect[0] + 5, rect[1] + 5, "rect", (0,0,255)) + + # ... + img.draw_string(a.x() + a.w() + 5, a.y(), "(" + str(a.x()) + "," + str(a.y()) + ")", (0,255,0)) + img.draw_string(a.cx(), a.cy(), "(" + str(a.cx()) + "," + str(a.cy()) + ")", (0,255,0)) + img.draw_string(a.x() + a.w() // 2, a.y(), str(a.w()), (0,255,0)) + img.draw_string(a.x(), a.y() + a.h() // 2, str(a.h()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 15, str(a.rotation_deg()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 30, "code:" + str(a.code()) + ", count:" + str(a.count()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 45, "perimeter:" + str(a.perimeter()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 60, "roundness:" + str(a.roundness()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 75, "elongation:" + str(a.elongation()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 90, "area:" + str(a.area()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 105, "density:" + str(round(a.density(), 2)), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 120, "extent:" + str(round(a.extent(), 2)), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 135, "compactness:" + str(round(a.compactness(), 2)), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 150, "solidity:" + str(a.solidity()), (0,255,0)) + img.draw_string(a.x() + a.w() + 5, a.y() + 165, "convexity:" + str(a.convexity()), (0,255,0)) + + # major axis line + major_axis_line = a.major_axis_line() + img.draw_line(major_axis_line[0], major_axis_line[1], major_axis_line[2], major_axis_line[3], (255,0,0)) + + # minor axis line + minor_axis_line = a.minor_axis_line() + img.draw_line(minor_axis_line[0], minor_axis_line[1], minor_axis_line[2], minor_axis_line[3], (0,0,255)) + + # enclosing circle + enclosing_circle = a.enclosing_circle() + img.draw_circle(enclosing_circle[0], enclosing_circle[1], enclosing_circle[2], (255,0,0)) + + # enclosing ellipse + enclosed_ellipse = a.enclosed_ellipse() + img.draw_ellipse(enclosed_ellipse[0], enclosed_ellipse[1], enclosed_ellipse[2], enclosed_ellipse[3], enclosed_ellipse[4], (0,0,255)) + + # hist(not use) + x_hist_bins = a.x_hist_bins() + y_hist_bins = a.y_hist_bins() + + lcd.display(img) + + + +# from maix import camera, display, image + +# cam = camera.Camera() +# cam.open(width = 640, height = 480) + +# screen = display.Display(device = None, width = 640, height = 480) +# screen.open() + +# roi = [160, 120, 320, 240] +# area_threshold = 1000 +# pixels_threshold = 1000 +# thresholds = [[0, 100, -120, -10, 0, 30]] +# invert = False +# x_stride = 2 +# y_stride = 1 +# merge = True +# margin = 10 +# x_hist_bins_max = 0 +# y_hist_bins_max = 0 +# while 1: +# img = cam.read() + +# blobs = img.find_blobs(thresholds, invert, roi, x_stride, y_stride, area_threshold, pixels_threshold, merge, margin, x_hist_bins_max, y_hist_bins_max) +# for a in blobs: +# # draw rect +# rect = a.rect() +# img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,255,0)) + +# # corners +# corners = a.corners() +# for i in range(4): +# img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], (255,0,0)) +# img.draw_string(corners[0][0] + 5, corners[0][1] + 5, "corners area: " + str(a.area()), (255,0,0)) + +# # mini_corners +# mini_corners = a.mini_corners() +# for i in range(4): +# img.draw_line(mini_corners[i][0], mini_corners[i][1], mini_corners[(i + 1) % 4][0], mini_corners[(i + 1) % 4][1], (0,255,0)) +# img.draw_string(mini_corners[0][0] + 5, mini_corners[0][1] + 5, "mini_corners", (0,255,0)) + +# # rect +# rect = a.rect() +# img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,0,255)) +# img.draw_string(rect[0] + 5, rect[1] + 5, "rect", (0,0,255)) + +# # ... +# img.draw_string(a.x() + a.w() + 5, a.y(), "(" + str(a.x()) + "," + str(a.y()) + ")", (0,255,0)) +# img.draw_string(a.cx(), a.cy(), "(" + str(a.cx()) + "," + str(a.cy()) + ")", (0,255,0)) +# img.draw_string(a.x() + a.w() // 2, a.y(), str(a.w()), (0,255,0)) +# img.draw_string(a.x(), a.y() + a.h() // 2, str(a.h()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 15, str(a.rotation_deg()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 30, "code:" + str(a.code()) + ", count:" + str(a.count()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 45, "perimeter:" + str(a.perimeter()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 60, "roundness:" + str(a.roundness()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 75, "elongation:" + str(a.elongation()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 90, "area:" + str(a.area()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 105, "density:" + str(round(a.density(), 2)), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 120, "extent:" + str(round(a.extent(), 2)), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 135, "compactness:" + str(round(a.compactness(), 2)), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 150, "solidity:" + str(a.solidity()), (0,255,0)) +# img.draw_string(a.x() + a.w() + 5, a.y() + 165, "convexity:" + str(a.convexity()), (0,255,0)) + +# # major axis line +# major_axis_line = a.major_axis_line() +# img.draw_line(major_axis_line[0], major_axis_line[1], major_axis_line[2], major_axis_line[3], (255,0,0)) + +# # minor axis line +# minor_axis_line = a.minor_axis_line() +# img.draw_line(minor_axis_line[0], minor_axis_line[1], minor_axis_line[2], minor_axis_line[3], (0,0,255)) + +# # enclosing circle +# enclosing_circle = a.enclosing_circle() +# img.draw_circle(enclosing_circle[0], enclosing_circle[1], enclosing_circle[2], (255,0,0)) + +# # enclosing ellipse +# enclosed_ellipse = a.enclosed_ellipse() +# img.draw_ellipse(enclosed_ellipse[0], enclosed_ellipse[1], enclosed_ellipse[2], enclosed_ellipse[3], enclosed_ellipse[4], 0, 360, (0,0,255)) + +# # hist(not use) +# x_hist_bins = a.x_hist_bins() +# y_hist_bins = a.y_hist_bins() + +# img.draw_rectangle(roi[0], roi[1], roi[2], roi[3], (0,255,0)) +# img.draw_string(roi[0] + 5, roi[1] + 5, "ROI", (0,255,0)) +# screen.show(img) diff --git a/examples/maixpy_v1/image/find_circles.py b/examples/maixpy_v1/image/find_circles.py new file mode 100644 index 0000000..bc1e849 --- /dev/null +++ b/examples/maixpy_v1/image/find_circles.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +while True: + img = sensor.snapshot() + + circles = img.find_circles(threshold = 3000) + for a in circles: + img.draw_circle(a.x(), a.y(), a.r(), (255,0,0), 2) + img.draw_string(a.x() + a.r() + 5, a.y() + a.r() + 5, "r: " + str(a.r()) + "magnitude: " + str(a.magnitude()), (255,0,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_edges.py b/examples/maixpy_v1/image/find_edges.py new file mode 100644 index 0000000..3c4dc84 --- /dev/null +++ b/examples/maixpy_v1/image/find_edges.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor, image +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +threshold = [100, 200] +edge_type = image.EDGE_CANNY + +while True: + img = sensor.snapshot() + + img.find_edges(edge_type, threshold) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_line_segments.py b/examples/maixpy_v1/image/find_line_segments.py new file mode 100644 index 0000000..ee59a4f --- /dev/null +++ b/examples/maixpy_v1/image/find_line_segments.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +while True: + img = sensor.snapshot() + + lines = img.find_line_segments(merge_distance = 20) + for a in lines: + img.draw_line(a.x1(), a.y1(), a.x2(), a.y2(), (255,0,0), 2) + theta = a.theta() + rho = a.rho() + angle_in_radians = math.radians(theta) + x = int(math.cos(angle_in_radians) * rho) + y = int(math.sin(angle_in_radians) * rho) + img.draw_line(0, 0, x, y, (0,255,255), 2) + img.draw_string(x, y, "theta: " + str(theta) + "," + "rho: " + str(rho), (0,255,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_lines.py b/examples/maixpy_v1/image/find_lines.py new file mode 100644 index 0000000..2d825b4 --- /dev/null +++ b/examples/maixpy_v1/image/find_lines.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +while True: + img = sensor.snapshot() + + lines = img.find_lines() + for a in lines: + img.draw_line(a.x1(), a.y1(), a.x2(), a.y2(), (255,0,0), 2) + theta = a.theta() + rho = a.rho() + angle_in_radians = math.radians(theta) + x = int(math.cos(angle_in_radians) * rho) + y = int(math.sin(angle_in_radians) * rho) + img.draw_line(0, 0, x, y, (0,255,255), 2) + img.draw_string(x, y, "theta: " + str(theta) + "," + "rho: " + str(rho), (0,255,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_qrcodes.py b/examples/maixpy_v1/image/find_qrcodes.py new file mode 100644 index 0000000..0db9149 --- /dev/null +++ b/examples/maixpy_v1/image/find_qrcodes.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.VGA) +sensor.run(1) + +roi = [160, 120, 320, 240] + +while True: + img = sensor.snapshot() + + qrcodes = img.find_qrcodes(roi) + for a in qrcodes: + # corners + corners = a.corners() + for i in range(4): + img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], (255,0,0)) + + # rect + rect = a.rect() + img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,0,255)) + img.draw_string(rect[0] + 5, rect[1] + 5, "rect", (0,0,255)) + + # payload + img.draw_string(a.x() + a.w() + 5, rect[1] + 20, "payload: " + a.payload(), (0,0,255)) + + # version + img.draw_string(a.x() + a.w() + 5, rect[1] + 35, "version: " + str(a.version()), (0,0,255)) + img.draw_string(a.x() + a.w() + 5, rect[1] + 50, "ecc_level: " + str(a.ecc_level()), (0,0,255)) + img.draw_string(a.x() + a.w() + 5, rect[1] + 65, "mask: " + str(a.mask()), (0,0,255)) + img.draw_string(a.x() + a.w() + 5, rect[1] + 80, "data_type: " + str(a.data_type()), (0,0,255)) + img.draw_string(a.x() + a.w() + 5, rect[1] + 95, "eci: " + str(a.eci()), (0,0,255)) + if a.is_numeric(): + img.draw_string(a.x() + a.w() + 5, rect[1] + 110, "is numeric", (0,0,255)) + elif a.is_alphanumeric(): + img.draw_string(a.x() + a.w() + 5, rect[1] + 110, "is alphanumeric", (0,0,255)) + elif a.is_binary(): + img.draw_string(a.x() + a.w() + 5, rect[1] + 110, "is binary", (0,0,255)) + elif a.is_kanji(): + img.draw_string(a.x() + a.w() + 5, rect[1] + 110, "is kanji", (0,0,255)) + else: + img.draw_string(a.x() + a.w() + 5, rect[1] + 110, "is unknown", (0,0,255)) + + img.draw_rectangle(roi[0], roi[1], roi[2], roi[3], (0,255,0)) + img.draw_string(roi[0] + 5, roi[1] + 5, "ROI", (0,255,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/find_rects.py b/examples/maixpy_v1/image/find_rects.py new file mode 100644 index 0000000..2de8231 --- /dev/null +++ b/examples/maixpy_v1/image/find_rects.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +while True: + img = sensor.snapshot() + + rects = img.find_rects(threshold = 10000) + for a in rects: + # corners + corners = a.corners() + for i in range(4): + img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], (255,0,0)) + + # rect + rect = a.rect() + img.draw_rectangle(rect[0], rect[1], rect[2], rect[3], (0,255,0)) + img.draw_string(rect[0] + 5, rect[1] + 5, "rect", (0,255,0)) + img.draw_string(rect[0] + 5, rect[1] + 20, "magnitude: " + str(a.magnitude()), (0,255,0)) + + lcd.display(img) \ No newline at end of file diff --git a/examples/maixpy_v1/image/flood_fill.py b/examples/maixpy_v1/image/flood_fill.py new file mode 100644 index 0000000..381845a --- /dev/null +++ b/examples/maixpy_v1/image/flood_fill.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() +img = image.Image("test.jpg") +img.flood_fill(50, 100) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/gaussian.py b/examples/maixpy_v1/image/gaussian.py new file mode 100644 index 0000000..c9bd138 --- /dev/null +++ b/examples/maixpy_v1/image/gaussian.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +size = 1 +kernel = [-1, -2, -1, -2, 6, -2, -1, -2, -1] + +lcd.init() +img = image.Image("test.jpg") +img.gaussian(2, mul = 1 / 8, add = 200) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/get_histogram.py b/examples/maixpy_v1/image/get_histogram.py new file mode 100644 index 0000000..914eeab --- /dev/null +++ b/examples/maixpy_v1/image/get_histogram.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time + +def draw_histogram(img, list, x, y, color): + l_len = len(list) + l_step = 2 + l_max = 100 + img.draw_line(x, y, x + l_step * l_len, y, (255,0,0)) + img.draw_line(x, y, x, y + l_max, (255,0,0)) + for i in range(l_len): + img.draw_rectangle(x + i * l_step, y, l_step, int(list[i] * img.width() * img.height() / 100), color) + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +thresholds = [[0, 80, 40, 80, 10, 80]] # red + +while True: + img = sensor.snapshot() + + hist = img.get_histogram(thresholds) + l_list = hist["L"] + a_list = hist["A"] + b_list = hist["B"] + draw_histogram(img, l_list, 50, 50, (255,0,0)) + draw_histogram(img, a_list, 50, 200, (0,255,0)) + draw_histogram(img, b_list, 50, 350, (0,0,255)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/get_regression.py b/examples/maixpy_v1/image/get_regression.py new file mode 100644 index 0000000..a708ad8 --- /dev/null +++ b/examples/maixpy_v1/image/get_regression.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time +import math + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +thresholds = [[0, 80, 40, 80, 10, 80]] # red + +while True: + img = sensor.snapshot() + + lines = img.get_regression(thresholds) + for a in lines: + img.draw_line(a.x1(), a.y1(), a.x2(), a.y2(), (255,0,0), 2) + theta = a.theta() + rho = a.rho() + angle_in_radians = math.radians(theta) + x = int(math.cos(angle_in_radians) * rho) + y = int(math.sin(angle_in_radians) * rho) + img.draw_line(0, 0, x, y, (0,255,255), 2) + img.draw_string(x, y, "theta: " + str(theta) + "," + "rho: " + str(rho), (0,255,0)) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/get_statistics.py b/examples/maixpy_v1/image/get_statistics.py new file mode 100644 index 0000000..0236cdc --- /dev/null +++ b/examples/maixpy_v1/image/get_statistics.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, sensor +from maix import time + +lcd.init() +sensor.reset() +sensor.set_framesize(sensor.QVGA) +sensor.run(1) + +thresholds = [[0, 80, 40, 80, 10, 80]] # red + +while True: + img = sensor.snapshot() + + statistics = img.get_statistics(thresholds) + print("L: mean {}, median {}, mode {}, std_dev {}, min {}, max {}, lq {}, uq {}\r\n", + statistics.l_mean(), statistics.l_median(), statistics.l_mode(), statistics.l_std_dev(), + statistics.l_min(), statistics.l_max(), statistics.l_lq(), statistics.l_uq()) + print("A: mean {}, median {}, mode {}, std_dev {}, min {}, max {}, lq {}, uq {}\r\n", + statistics.a_mean(), statistics.a_median(), statistics.a_mode(), statistics.a_std_dev(), + statistics.a_min(), statistics.a_max(), statistics.a_lq(), statistics.a_uq()) + print("B: mean {}, median {}, mode {}, std_dev {}, min {}, max {}, lq {}, uq {}\r\n", + statistics.b_mean(), statistics.b_median(), statistics.b_mode(), statistics.b_std_dev(), + statistics.b_min(), statistics.b_max(), statistics.b_lq(), statistics.b_uq()) + + lcd.display(img) diff --git a/examples/maixpy_v1/image/histeq.py b/examples/maixpy_v1/image/histeq.py new file mode 100644 index 0000000..24d069e --- /dev/null +++ b/examples/maixpy_v1/image/histeq.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +img.histeq() +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) \ No newline at end of file diff --git a/examples/maixpy_v1/image/invert.py b/examples/maixpy_v1/image/invert.py new file mode 100644 index 0000000..0ce5a65 --- /dev/null +++ b/examples/maixpy_v1/image/invert.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() +img = image.Image("test.jpg") +img.binary([[0, 50]]) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/invert_format.py b/examples/maixpy_v1/image/invert_format.py new file mode 100644 index 0000000..3dc5169 --- /dev/null +++ b/examples/maixpy_v1/image/invert_format.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +from maix import image as maix_img + +lcd.init() +img = image.Image("test.jpg") + +print('invert format to grayscale') +img.to_grayscale() +lcd.display(img) +time.sleep(1) + +print('invert format to rgb888') +img.to_rgb888() +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/laplacian.py b/examples/maixpy_v1/image/laplacian.py new file mode 100644 index 0000000..fc0dd89 --- /dev/null +++ b/examples/maixpy_v1/image/laplacian.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +size = 1 +kernel = [-1, -2, -1, -2, 6, -2, -1, -2, -1] + +lcd.init() +img = image.Image("test.jpg") +img.laplacian(2, mul = 1 / 8, add = 200) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/linpolar_logpolar.py b/examples/maixpy_v1/image/linpolar_logpolar.py new file mode 100644 index 0000000..e1ea73d --- /dev/null +++ b/examples/maixpy_v1/image/linpolar_logpolar.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# linpolar +img = image.Image("test.jpg") +img.linpolar() +lcd.display(img) +time.sleep(1) + +# logpolar +img = image.Image("test.jpg") +img.logpolar() +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/load_image.py b/examples/maixpy_v1/image/load_image.py new file mode 100644 index 0000000..0edfc4e --- /dev/null +++ b/examples/maixpy_v1/image/load_image.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/mean.py b/examples/maixpy_v1/image/mean.py new file mode 100644 index 0000000..79c44da --- /dev/null +++ b/examples/maixpy_v1/image/mean.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +img.mean(2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) \ No newline at end of file diff --git a/examples/maixpy_v1/image/midpoint.py b/examples/maixpy_v1/image/midpoint.py new file mode 100644 index 0000000..3f46352 --- /dev/null +++ b/examples/maixpy_v1/image/midpoint.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +img.midpoint(2, bias = 0.5) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/min_max.py b/examples/maixpy_v1/image/min_max.py new file mode 100644 index 0000000..ac4d4f5 --- /dev/null +++ b/examples/maixpy_v1/image/min_max.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# min +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.min(img2) +lcd.display(img) +time.sleep(1) + +# max +img = image.Image("test.jpg") +img2 = image.Image("test2.jpg") +img.max(img2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/mode.py b/examples/maixpy_v1/image/mode.py new file mode 100644 index 0000000..49d95fa --- /dev/null +++ b/examples/maixpy_v1/image/mode.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# difference +img = image.Image("test.jpg") +img.mode(2) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/morph.py b/examples/maixpy_v1/image/morph.py new file mode 100644 index 0000000..d862153 --- /dev/null +++ b/examples/maixpy_v1/image/morph.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +size = 1 +kernel = [-1, -2, -1, -2, 6, -2, -1, -2, -1] + +lcd.init() +img = image.Image("test.jpg") +img.morph(size, kernel, mul = 1 / 8, add = 200) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/negate.py b/examples/maixpy_v1/image/negate.py new file mode 100644 index 0000000..4698450 --- /dev/null +++ b/examples/maixpy_v1/image/negate.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# negate +img = image.Image("test.jpg") +img.negate() +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/pool.py b/examples/maixpy_v1/image/pool.py new file mode 100644 index 0000000..1f2ddd8 --- /dev/null +++ b/examples/maixpy_v1/image/pool.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +img = image.Image("test.jpg") +img.mean_pool(2, 2) +lcd.display(img) +time.sleep(1) + +img = image.Image("test.jpg") +img.midpoint_pool(3, 3) +lcd.display(img) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/replace.py b/examples/maixpy_v1/image/replace.py new file mode 100644 index 0000000..6ac1cb1 --- /dev/null +++ b/examples/maixpy_v1/image/replace.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +from maix.v1 import lcd, image +from maix import time + +lcd.init() + +# replace +img = image.Image("test.jpg") +img.replace(image = None, hmirror = False, vflip = True) +lcd.display(img) +time.sleep(1) + +img = image.Image("test.jpg") +img.replace(image = None, hmirror = True, vflip = True) +lcd.display(img) +time.sleep(1) + +img = image.Image("test.jpg") +img.replace(image = None, hmirror = True, vflip = False) +lcd.display(img) +time.sleep(1) + +img = image.Image("test.jpg") +img.replace(image = None, hmirror = False, vflip = False) +lcd.display(img) +time.sleep(1) + +while True: + time.sleep(1) diff --git a/examples/maixpy_v1/image/set_pixel.py b/examples/maixpy_v1/image/set_pixel.py new file mode 100644 index 0000000..ce9e3aa --- /dev/null +++ b/examples/maixpy_v1/image/set_pixel.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +from maix.v1 import image + +img = image.Image("test.jpg") + +# get old pixels +old_pixel = img.get_pixel(20, 50, True) +print('get old pixel, img({},{}) = {}'.format(20, 50, old_pixel)) + +# set new pixels +new_pixel = (10, 20, 30) +img.set_pixel(20, 50, new_pixel) +print('set new pixel, img({},{}) = {}'.format(20, 50, new_pixel)) + +# get curr pixels +curr_pixel = img.get_pixel(20, 50, True) +print('get curr pixel, img({},{}) = {}'.format(20, 50, curr_pixel)) diff --git a/examples/maixpy_v1/test_lcd.py b/examples/maixpy_v1/lcd.py similarity index 94% rename from examples/maixpy_v1/test_lcd.py rename to examples/maixpy_v1/lcd.py index 9f12f01..cb1ba02 100644 --- a/examples/maixpy_v1/test_lcd.py +++ b/examples/maixpy_v1/lcd.py @@ -6,7 +6,9 @@ img = image.Image("test.jpg") lcd.init() +lcd.mirror(1) lcd.display(img) + # lcd.clear() print('lcd width:', lcd.width()) print('lcd height:', lcd.height()) diff --git a/examples/maixpy_v1/test_sensor.py b/examples/maixpy_v1/sensor.py similarity index 75% rename from examples/maixpy_v1/test_sensor.py rename to examples/maixpy_v1/sensor.py index f40fd3d..3b3522f 100644 --- a/examples/maixpy_v1/test_sensor.py +++ b/examples/maixpy_v1/sensor.py @@ -5,7 +5,11 @@ lcd.init() sensor.reset() -# sensor.set_pixformat(sensor.RGB565) +sensor.set_hmirror(0) +sensor.set_vflip(0) +sensor.set_brightness(1) +sensor.set_contrast(10) +sensor.set_saturation(80) sensor.set_framesize(sensor.VGA) sensor.run(1) sensor.skip_frames(1) diff --git a/examples/maixpy_v1/test_image.py b/examples/maixpy_v1/test_image.py deleted file mode 100644 index 4c72e62..0000000 --- a/examples/maixpy_v1/test_image.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -from maix.v1 import lcd, image -from maix import time - -lcd.init() -print('lcd width:', lcd.width()) -print('lcd height:', lcd.height()) - -img = image.Image("test.jpg") -print('img width:', img.width()) -print('img height:', img.height()) -print('img format:', img.format()) -print('img data size:', img.size()) -lcd.display(img) - -while True: - time.sleep(1) diff --git a/maix/v1/image.py b/maix/v1/image.py index e68c269..beadb37 100644 --- a/maix/v1/image.py +++ b/maix/v1/image.py @@ -32,711 +32,587 @@ CODE93 = 14 CODE128 = 15 -class Histogram: - def __init__(self): - raise ValueError('This operation is not supported') - - def bins(self): - raise ValueError('This operation is not supported') - - def l_bins(self): - raise ValueError('This operation is not supported') - - def a_bins(self): - raise ValueError('This operation is not supported') - - def b_bins(self): - raise ValueError('This operation is not supported') - - def get_percentile(self, percentile): - raise ValueError('This operation is not supported') - - def get_threhsold(self): - raise ValueError('This operation is not supported') - - def get_statistics(self): - raise ValueError('This operation is not supported') - -class Statistics: - def __init__(self): - raise ValueError('This operation is not supported') - - def mean(self): - raise ValueError('This operation is not supported') - - def median(self): - raise ValueError('This operation is not supported') - - def mode(self): - raise ValueError('This operation is not supported') - - def stdev(self): - raise ValueError('This operation is not supported') - - def min(self): - raise ValueError('This operation is not supported') - - def max(self): - raise ValueError('This operation is not supported') - - def lq(self): - raise ValueError('This operation is not supported') - - def uq(self): - raise ValueError('This operation is not supported') - - def l_mean(self): - raise ValueError('This operation is not supported') - - def l_median(self): - raise ValueError('This operation is not supported') - - def l_mode(self): - raise ValueError('This operation is not supported') - - def l_stdev(self): - raise ValueError('This operation is not supported') - - def l_min(self): - raise ValueError('This operation is not supported') - - def l_max(self): - raise ValueError('This operation is not supported') - - def l_lq(self): - raise ValueError('This operation is not supported') - - def l_uq(self): - raise ValueError('This operation is not supported') - - def a_mean(self): - raise ValueError('This operation is not supported') - - def a_median(self): - raise ValueError('This operation is not supported') - - def a_mode(self): - raise ValueError('This operation is not supported') - - def a_stdev(self): - raise ValueError('This operation is not supported') - - def a_min(self): - raise ValueError('This operation is not supported') - - def a_max(self): - raise ValueError('This operation is not supported') - - def a_lq(self): - raise ValueError('This operation is not supported') - - def a_uq(self): - raise ValueError('This operation is not supported') - - def b_mean(self): - raise ValueError('This operation is not supported') - - def b_median(self): - raise ValueError('This operation is not supported') - - def b_mode(self): - raise ValueError('This operation is not supported') - - def b_stdev(self): - raise ValueError('This operation is not supported') - - def b_min(self): - raise ValueError('This operation is not supported') - - def b_max(self): - raise ValueError('This operation is not supported') - - def b_lq(self): - raise ValueError('This operation is not supported') - - def b_uq(self): - raise ValueError('This operation is not supported') - -class Blob: - def __init__(self): - raise ValueError('This operation is not supported') - - def rect(self): - raise ValueError('This operation is not supported') - - def x(self): - raise ValueError('This operation is not supported') - - def y(self): - raise ValueError('This operation is not supported') - - def w(self): - raise ValueError('This operation is not supported') - - def h(self): - raise ValueError('This operation is not supported') - - def pixels(self): - raise ValueError('This operation is not supported') - - def cx(self): - raise ValueError('This operation is not supported') - - def cy(self): - raise ValueError('This operation is not supported') - - def rotation(self): - raise ValueError('This operation is not supported') - - def code(self): - raise ValueError('This operation is not supported') - - def count(self): - raise ValueError('This operation is not supported') - - def area(self): - raise ValueError('This operation is not supported') - - def density(self): - raise ValueError('This operation is not supported') - -class Line: - def __init__(self): - raise ValueError('This operation is not supported') - - def line(self): - raise ValueError('This operation is not supported') - - def x1(self): - raise ValueError('This operation is not supported') - - def y1(self): - raise ValueError('This operation is not supported') - - def x2(self): - raise ValueError('This operation is not supported') - - def y2(self): - raise ValueError('This operation is not supported') - - def length(self): - raise ValueError('This operation is not supported') - - def magnitude(self): - raise ValueError('This operation is not supported') - - def theta(self): - raise ValueError('This operation is not supported') - - def rho(self): - raise ValueError('This operation is not supported') - - -class Circle: - def __init__(self): - raise ValueError('This operation is not supported') - - def x(self): - raise ValueError('This operation is not supported') - - def y(self): - raise ValueError('This operation is not supported') - - def r(self): - raise ValueError('This operation is not supported') - - def magnitude(self): - raise ValueError('This operation is not supported') - - -class Rect: - def __init__(self): - raise ValueError('This operation is not supported') - - def corners(self): - raise ValueError('This operation is not supported') - - def rect(self): - raise ValueError('This operation is not supported') - - def x(self): - raise ValueError('This operation is not supported') - - def y(self): - raise ValueError('This operation is not supported') - - def w(self): - raise ValueError('This operation is not supported') - - def h(self): - raise ValueError('This operation is not supported') - - def magnitude(self): - raise ValueError('This operation is not supported') - - -class QRCode: - def __init__(self): - raise ValueError('This operation is not supported') - - def corners(self): - raise ValueError('This operation is not supported') - - def rect(self): - raise ValueError('This operation is not supported') - - def x(self): - raise ValueError('This operation is not supported') - - def y(self): - raise ValueError('This operation is not supported') - - def w(self): - raise ValueError('This operation is not supported') - - def h(self): - raise ValueError('This operation is not supported') - - def payload(self): - raise ValueError('This operation is not supported') - - def version(self): - raise ValueError('This operation is not supported') +class Image: + def __init__(self, path=None, copy_to_fb=False, width=640, height=480, do_nothing = False): + if do_nothing: + self.__img = None + else: + if path is None: + self.__img = image.Image(width, height) + else: + self.__img = image.load(path) - def ecc_level(self): - raise ValueError('This operation is not supported') + def get_priv_img(self): + return self.__img - def mask(self): - raise ValueError('This operation is not supported') + def set_priv_img(self, new_image): + self.__img = new_image - def data_type(self): - raise ValueError('This operation is not supported') + def width(self): + return self.__img.width() - def eci(self): - raise ValueError('This operation is not supported') + def height(self): + return self.__img.height() - def is_numeric(self): - raise ValueError('This operation is not supported') + def format(self): + format_int = 0 + if self.__img.format() == image.Format.FMT_GRAYSCALE: + return 1 + elif self.__img.format() == image.Format.FMT_RGB565: + return 2 + elif self.__img.format() == image.Format.FMT_RGB888: + return 4 + elif self.__img.format() == image.Format.FMT_YVU420SP: + return 5 + else: + raise ValueError('Unknowed format') - def is_alphanumeric(self): - raise ValueError('This operation is not supported') + def size(self): + return self.__img.data_size() - def is_binary(self): - raise ValueError('This operation is not supported') + def get_pixel(self, x, y, rgbtuple = False): + return self.__img.get_pixel(x, y, rgbtuple) - def is_kanji(self): - raise ValueError('This operation is not supported') + def set_pixel(self, x, y, pixel): + self.__img.set_pixel(x, y, pixel) + def mean_pool(self, x_div, y_div): + img = self.__img.mean_pool(x_div, y_div, copy = False) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 -class AprilTag: - def __init__(self): - raise ValueError('This operation is not supported') + def mean_pooled(self, x_div, y_div): + return self.mean_pool(x_div, y_div) - def corners(self): - raise ValueError('This operation is not supported') + def midpoint_pool(self, x_div, y_div, bias=0.5): + img = self.__img.midpoint_pool(x_div, y_div, bias, copy = False) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 - def rect(self): - raise ValueError('This operation is not supported') + def midpoint_pooled(self, x_div, y_div, bias=0.5): + return self.midpoint_pooled(x_div, y_div, bias) - def x(self): - raise ValueError('This operation is not supported') + def to_grayscale(self, copy=False): + img = self.__img.to_format(image.Format.FMT_GRAYSCALE) + if copy is True: + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 + else: + self.__img = img + return self - def y(self): + def to_rgb565(self, copy=False): raise ValueError('This operation is not supported') - def w(self): - raise ValueError('This operation is not supported') + def to_rgb888(self, copy=False): + img = self.__img.to_format(image.Format.FMT_RGB888) + if copy is True: + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 + else: + self.__img = img + return self - def h(self): + def to_rainbow(self, copy=False): raise ValueError('This operation is not supported') - def id(self): - raise ValueError('This operation is not supported') + def compress(self, quality=50): + img = self.__img.compress(quality) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 - def family(self): + def compress_for_ide(self, quality=50): raise ValueError('This operation is not supported') - def cx(self): - raise ValueError('This operation is not supported') + def copy(self, roi=[], copy_to_fb=False): + img = self.__img.copy() + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 - def cy(self): - raise ValueError('This operation is not supported') + def save(self, path, roi=[], quality=50): + img = self.__img.save(path, quality) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 - def rotation(self): - raise ValueError('This operation is not supported') + def clear(self): + self.__img.clear() - def decision_margin(self): - raise ValueError('This operation is not supported') + def draw_line(self, x0, y0, x1, y1, color, thickness=1): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def hamming(self): - raise ValueError('This operation is not supported') + self.__img.draw_line(x0, y0, x1, y1, img_color, thickness) + return self - def goodness(self): - raise ValueError('This operation is not supported') + def draw_rectangle(self, x, y, w, h, color, thickness=1, fill=False): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def x_translation(self): - raise ValueError('This operation is not supported') + if fill: + self.__img.draw_rect(x, y, w, h, img_color, -1) + else: + self.__img.draw_rect(x, y, w, h, img_color, thickness) - def y_translation(self): - raise ValueError('This operation is not supported') + def draw_ellipse(self, cx, cy, rx, ry, rotation, color, thickness=1, fill=False): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def z_translation(self): - raise ValueError('This operation is not supported') + if fill: + self.__img.draw_ellipse(cx, cy, rx, ry, rotation, 0, 360, img_color, thickness=-1) + else: + self.__img.draw_ellipse(cx, cy, rx, ry, rotation, 0, 360, img_color, thickness=thickness) - def x_rotation(self): - raise ValueError('This operation is not supported') + def draw_circle(self, x, y, radius, color, thickness=1, fill=False): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def y_rotation(self): - raise ValueError('This operation is not supported') + if fill: + self.__img.draw_circle(x, y, radius, img_color, thickness=-1) + else: + self.__img.draw_circle(x, y, radius, img_color, thickness=thickness) - def z_rotation(self): - raise ValueError('This operation is not supported') -class DataMatrix: - def __init__(self): - raise ValueError('This operation is not supported') + def draw_string(self, x, y, text, color, scale=1, x_spacing=0, y_spacing=0, mono_space=True): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def corners(self): - raise ValueError('This operation is not supported') + self.__img.draw_string(x, y, text, img_color, scale) - def rect(self): - raise ValueError('This operation is not supported') + def draw_cross(self, x, y, color, size=5, thickness=1): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def x(self): - raise ValueError('This operation is not supported') + self.__img.draw_cross(x, y, img_color, size, thickness=thickness) - def y(self): - raise ValueError('This operation is not supported') + def draw_arrow(self, x0, y0, x1, y1, color, thickness=1): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def w(self): - raise ValueError('This operation is not supported') + self.__img.draw_arrow(x0, y0, x1, y1, img_color, thickness=thickness) - def h(self): - raise ValueError('This operation is not supported') + def draw_image(self, image, x, y, x_scale=1.0, y_scale=1.0, mask=None, alpha=256): + img = image.get_priv_img() + print(x, y, img.width(), img.height()) + self.__img.draw_image(x, y, img) - def payload(self): - raise ValueError('This operation is not supported') - def rotation(self): - raise ValueError('This operation is not supported') + def draw_keypoints(self, keypoints, color, size=10, thickness=1, fill=False): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def rows(self): - raise ValueError('This operation is not supported') + if fill: + self.__img.draw_keypoints(keypoints, img_color, size, thickness=-1) + else: + self.__img.draw_keypoints(keypoints, img_color, size, thickness=thickness) - def columns(self): - raise ValueError('This operation is not supported') + def flood_fill(self, x, y, seed_threshold=0.05, floating_threshold=0.05, color=(255,255,255), invert=False, clear_background=False, mask=None): + img_color = None + if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: + img_color = image.Color.from_rgb(color[0], color[1], color[2]) + elif isinstance(color, int): + img_color = image.Color.from_rgb(color, color, color) - def capacity(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + self.__img.flood_fill(x, y, seed_threshold, floating_threshold, img_color, invert, clear_background, mask_img) - def padding(self): - raise ValueError('This operation is not supported') + def binary(self, thresholds, invert=False, zero=False, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + self.__img.binary(thresholds, invert, zero, mask_img) -class BarCode: - def __init__(self): - raise ValueError('This operation is not supported') + def invert(self): + img = self.__img.invert() + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + return img_v1 - def corners(self): - raise ValueError('This operation is not supported') + def b_and(self, image, mask=None): + other_img = image.get_priv_img() - def rect(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def x(self): - raise ValueError('This operation is not supported') + img = self.__img.b_and(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def y(self): - raise ValueError('This operation is not supported') + return img_v1 - def w(self): - raise ValueError('This operation is not supported') + def b_nand(self, image, mask=None): + other_img = image.get_priv_img() - def h(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def payload(self): - raise ValueError('This operation is not supported') + img = self.__img.b_nand(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def type(self): - raise ValueError('This operation is not supported') + return img_v1 - def rotation(self): - raise ValueError('This operation is not supported') + def b_or(self, image, mask=None): + other_img = image.get_priv_img() - def quality(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() -class Displacement: - def __init__(self): - raise ValueError('This operation is not supported') + img = self.__img.b_or(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def x_translation(self): - raise ValueError('This operation is not supported') + return img_v1 - def y_translation(self): - raise ValueError('This operation is not supported') + def b_nor(self, image, mask=None): + other_img = image.get_priv_img() - def rotation(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def scale(self): - raise ValueError('This operation is not supported') + img = self.__img.b_nor(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def response(self): - raise ValueError('This operation is not supported') + return img_v1 -class Image: - def __init__(self, path=None, copy_to_fb=False, width=640, height=480, do_nothing = False): - if do_nothing: - self.__img = None - else: - if path is None: - self.__img = image.Image(width, height) - else: - self.__img = image.load(path) + def b_xor(self, image, mask=None): + other_img = image.get_priv_img() - def get_priv_img(self): - return self.__img + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def set_priv_img(self, new_image): - self.__img = new_image + img = self.__img.b_xor(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def width(self): - return self.__img.width() + return img_v1 - def height(self): - return self.__img.height() + def b_xnor(self, image, mask=None): + other_img = image.get_priv_img() - def format(self): - format_int = 0 - if self.__img.format() == image.Format.FMT_GRAYSCALE: - return 1 - elif self.__img.format() == image.Format.FMT_RGB565: - return 2 - elif self.__img.format() == image.Format.FMT_RGB888: - return 4 - elif self.__img.format() == image.Format.FMT_YVU420SP: - return 5 - else: - raise ValueError('Unknowed format') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def size(self): - return self.__img.data_size() + img = self.__img.b_xnor(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def get_pixel(self, x, y, rgbtuple = False): - return self.__img.get_pixel(x, y, rgbtuple) + return img_v1 - def set_pixel(self, x, y, pixel): - self.__img.set_pixel(x, y, pixel) + def erode(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def mean_pool(self, x_div, y_div): - img = self.__img.mean_pool(x_div, y_div, copy = False) + img = self.__img.erode(size, threshold, mask_img) img_v1 = Image(do_nothing=True) img_v1.set_priv_img(img) + return img_v1 - def mean_pooled(self, x_div, y_div): - return self.mean_pool(x_div, y_div) + def dilate(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def midpoint_pool(self, x_div, y_div, bias=0.5): - img = self.__img.midpoint_pool(x_div, y_div, bias, copy = False) + img = self.__img.dilate(size, threshold, mask_img) img_v1 = Image(do_nothing=True) img_v1.set_priv_img(img) + return img_v1 - def midpoint_pooled(self, x_div, y_div, bias=0.5): - return self.midpoint_pooled(x_div, y_div, bias) + def open(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def to_grayscale(self, copy=False): - img = self.__img.to_format(image.Format.FMT_GRAYSCALE) - if copy: - img_v1 = Image(do_nothing=True) - img_v1.set_priv_img(img) - return img_v1 - else: - self.__img = img - return self + img = self.__img.open(size, threshold, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def to_rgb565(self, copy=False): - raise ValueError('This operation is not supported') + return img_v1 - def to_rainbow(self, copy=False): - raise ValueError('This operation is not supported') + def close(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def compress(self, quality=50): - img = self.__img.compress(quality) + img = self.__img.close(size, threshold, mask_img) img_v1 = Image(do_nothing=True) img_v1.set_priv_img(img) + return img_v1 - def compress_for_ide(self, quality=50): - raise ValueError('This operation is not supported') + def top_hat(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def copy(self, roi=None, copy_to_fb=False): - img = self.__img.copy() + img = self.__img.top_hat(size, threshold, mask_img) img_v1 = Image(do_nothing=True) img_v1.set_priv_img(img) + return img_v1 - def save(self, path, roi=None, quality=50): - img = self.__img.save(path, quality) + def black_hat(self, size, threshold, mask=None): + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.black_hat(size, threshold, mask_img) img_v1 = Image(do_nothing=True) img_v1.set_priv_img(img) + return img_v1 - def clear(self): - self.__img.clear() + def negate(self): + img = self.__img.negate() + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def draw_line(self, x0, y0, x1, y1, color, thickness=1): - img_color = None - if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: - img_color = image.Color.from_rgb(color[0], color[1], color[2]) - elif isinstance(color, int): - img_color = image.Color.from_rgb(color, color, color) + return img_v1 - self.__img.draw_line(x0, y0, x1, y1, img_color, thickness) - return self + def replace(self, image, hmirror=False, vflip=False, mask=None): + other_img = None + if image is not None: + other_img = image.get_priv_img() - def draw_rectangle(self, x, y, w, h, color, thickness=1, fill=False): - img_color = None - if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: - img_color = image.Color.from_rgb(color[0], color[1], color[2]) - elif isinstance(color, int): - img_color = image.Color.from_rgb(color, color, color) + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - if fill: - self.__img.draw_rect(x, y, w, h, img_color, -1) - else: - self.__img.draw_rect(x, y, w, h, img_color, thickness) + img = self.__img.replace(other_img, hmirror, vflip, mask=mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def draw_ellipse(self, cx, cy, rx, ry, rotation, color, thickness=1, fill=False): - img_color = None - if isinstance(color, tuple) or isinstance(color, list) and len(color) > 2: - img_color = image.Color.from_rgb(color[0], color[1], color[2]) - elif isinstance(color, int): - img_color = image.Color.from_rgb(color, color, color) + return img_v1 - if fill: - self.__img.draw_ellipse(cx, cy, rx, ry, rotation, 0, 360, img_color, thickness=-1) - else: - self.__img.draw_ellipse(cx, cy, rx, ry, rotation, 0, 360, img_color, thickness=thickness) + def add(self, image, mask=None): + other_img = image.get_priv_img() - def draw_circle(self, x, y, radius, color, thickness=1, fill=False): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def draw_string(self, x, y, text, color, scale=1, x_spacing=0, y_spacing=0, mono_space=True): - raise ValueError('This operation is not supported') + img = self.__img.add(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def draw_cross(self, x, y, color, size=5, thickness=1): - raise ValueError('This operation is not supported') + return img_v1 - def draw_arrow(self, x0, y0, x1, y1, color, thickness=1): - raise ValueError('This operation is not supported') + def sub(self, image, reverse=False, mask=None): + other_img = image.get_priv_img() - def draw_image(self, image, x, y, x_scale=1.0, y_scale=1.0, mask=None, alpha=256): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def draw_keypoints(self, keypoints, color, size=10, thickness=1, fill=False): - raise ValueError('This operation is not supported') + img = self.__img.sub(other_img, reverse, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def flood_fill(self, x, y, seed_threshold=0.05, floating_threshold=0.05, color=(255,255,255), invert=False, clear_background=False, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def binary(self, thresholds, invert=False, zero=False, mask=None): - raise ValueError('This operation is not supported') + def mul(self, image, invert=False, mask=None): + other_img = image.get_priv_img() - def invert(self): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def b_and(self, image, mask=None): - raise ValueError('This operation is not supported') + img = self.__img.mul(other_img, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def b_nand(self, image, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def b_or(self, image, mask=None): - raise ValueError('This operation is not supported') + def div(self, image, invert=False, mask=None): + other_img = image.get_priv_img() - def b_nor(self, image, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def b_xor(self, image, mask=None): - raise ValueError('This operation is not supported') + img = self.__img.div(other_img, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def b_xnor(self, image, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def erode(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + def min(self, image, mask=None): + other_img = image.get_priv_img() - def dilate(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def open(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + img = self.__img.min(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def close(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def top_hat(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + def max(self, image, mask=None): + other_img = image.get_priv_img() - def black_hat(self, size, threshold, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def negate(self): - raise ValueError('This operation is not supported') + img = self.__img.max(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def replace(self, image, hmirror=False, vflip=False, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def add(self, image, mask=None): - raise ValueError('This operation is not supported') + def difference(self, image, mask=None): + other_img = image.get_priv_img() - def sub(self, image, reverse=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def mul(self, image, invert=False, mask=None): - raise ValueError('This operation is not supported') + img = self.__img.difference(other_img, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def div(self, image, invert=False, mask=None): - raise ValueError('This operation is not supported') + return img_v1 - def min(self, image, mask=None): - raise ValueError('This operation is not supported') + def blend(self, image, alpha=128, mask=None): + other_img = image.get_priv_img() - def max(self, image, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() - def difference(self, image, mask=None): - raise ValueError('This operation is not supported') + img = self.__img.blend(other_img, alpha, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) - def blend(self, image, alpha=128, mask=None): - raise ValueError('This operation is not supported') + return img_v1 def histeq(self, adaptive=False, clip_limit=-1, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.histeq(adaptive, clip_limit, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def mean(self, size, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.mean(size, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def mode(self, size, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.mode(size, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def midpoint(self, size, bias=0.5, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.midpoint(size, bias, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def morph(self, size, kernel, mul=-1, add=0): - raise ValueError('This operation is not supported') + img = self.__img.morph(size, kernel, mul, add) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def gaussian(self, size, unsharp=False, mul=-1, add=0, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.gaussian(size, unsharp, mul, add, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def laplacian(self, size, sharpen=False, mul=-1, add=0, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.laplacian(size, sharpen, mul, add, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def bilateral(self, size, color_sigma=0.1, space_sigma=1, threshold=False, offset=0, invert=False, mask=None): - raise ValueError('This operation is not supported') + mask_img = None + if mask is not None: + mask_img = mask.get_priv_img() + + img = self.__img.bilateral(size, color_sigma, space_sigma, threshold, offset, invert, mask_img) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def cartoon(self, size, seed_threshold=0.05, floating_threshold=0.05, mask=None): raise ValueError('This operation is not supported') @@ -751,70 +627,96 @@ def illuminvar(self): raise ValueError('This operation is not supported') def linpolar(self, reverse=False): - raise ValueError('This operation is not supported') + img = self.__img.linpolar(reverse) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def logpolar(self, reverse=False): - raise ValueError('This operation is not supported') + img = self.__img.logpolar(reverse) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def lens_corr(self, strength=1.8, zoom=1.0): - raise ValueError('This operation is not supported') + img = self.__img.lens_corr(strength, zoom) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def rotation_corr(self, x_rotation=0.0, y_rotation=0.0, z_rotation=0.0, x_translation=0.0, y_translation=0.0, zoom=1.0, fov=60.0, corners=None): - raise ValueError('This operation is not supported') + img = self.__img.rotation_corr(x_rotation, y_rotation, z_rotation, x_translation, y_translation, zoom, fov, corners) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def get_similarity(self, image): raise ValueError('This operation is not supported') - def get_histogram(self, thresholds, invert=False, roi=None, bins=None, l_bins=None, a_bins=None, b_bins=None): - raise ValueError('This operation is not supported') + def get_histogram(self, thresholds, invert=False, roi=[], bins=-1, l_bins=100, a_bins=256, b_bins=256): + return self.__img.get_histogram(thresholds, invert, roi, bins, l_bins, a_bins, b_bins, None) - def get_statistics(self, thresholds, invert=False, roi=None, bins=None, l_bins=None, a_bins=None, b_bins=None): - raise ValueError('This operation is not supported') + def get_statistics(self, thresholds, invert=False, roi=[], bins=-1, l_bins=100, a_bins=256, b_bins=256): + return self.__img.get_statistics(thresholds, invert, roi, bins, l_bins, a_bins, b_bins, None) - def get_regression(self, thresholds, invert=False, roi=None, x_stride=2, y_stride=1, area_threshold=10, pixels_threshold=10, robust=False): - raise ValueError('This operation is not supported') + def get_regression(self, thresholds, invert=False, roi=[], x_stride=2, y_stride=1, area_threshold=10, pixels_threshold=10, robust=False): + return self.__img.get_regression(thresholds, invert, roi, x_stride, y_stride, area_threshold, pixels_threshold, robust) - def find_blobs(self, thresholds, invert=False, roi=None, x_stride=2, y_stride=1, area_threshold=10, pixels_threshold=10, merge=False, margin=0, threshold_cb=None, merge_cb=None): - raise ValueError('This operation is not supported') + def find_blobs(self, thresholds, invert=False, roi=[], x_stride=2, y_stride=1, area_threshold=10, pixels_threshold=10, merge=False, margin=0, threshold_cb=None, merge_cb=None): + return self.__img.find_blobs(thresholds, invert, roi, x_stride, y_stride, area_threshold, pixels_threshold, merge, margin) - def find_lines(self, roi=None, x_stride=2, y_stride=1, threshold=1000, theta_margin=25, rho_margin=25): - raise ValueError('This operation is not supported') + def find_lines(self, roi=[], x_stride=2, y_stride=1, threshold=1000, theta_margin=25, rho_margin=25): + return self.__img.find_lines(roi, x_stride, y_stride, threshold, theta_margin, rho_margin) - def find_line_segments(self, roi=None, merge_distance=0, max_theta_difference=15): - raise ValueError('This operation is not supported') + def find_line_segments(self, roi=[], merge_distance=0, max_theta_difference=15): + return self.__img.find_line_segments(roi, merge_distance, max_theta_difference) - def find_circles(self, roi=None, x_stride=2, y_stride=1, threshold=2000, x_margin=10, y_margin=10, r_margin=10): - raise ValueError('This operation is not supported') + def find_circles(self, roi=[], x_stride=2, y_stride=1, threshold=2000, x_margin=10, y_margin=10, r_margin=10): + return self.__img.find_circles(roi, x_stride, y_stride, threshold, x_margin, y_margin, r_margin) - def find_rects(self, roi=None, threshold=10000): - raise ValueError('This operation is not supported') + def find_rects(self, roi=[], threshold=10000): + return self.__img.find_rects(roi, threshold) - def find_qrcodes(self, roi=None): - raise ValueError('This operation is not supported') + def find_qrcodes(self, roi=[]): + return self.__img.find_qrcodes(roi) - def find_barcodes(self, roi=None): - raise ValueError('This operation is not supported') + def find_barcodes(self, roi=[]): + return self.__img.find_barcodes(roi) - def find_number(self, roi=None): + def find_number(self, roi=[]): raise ValueError('This operation is not supported') - def classify_object(self, roi=None): + def classify_object(self, roi=[]): raise ValueError('This operation is not supported') - def find_features(self, cascade, threshold=0.5, scale=1.5, roi=None): + def find_features(self, cascade, threshold=0.5, scale=1.5, roi=[]): raise ValueError('This operation is not supported') - def find_eye(self, roi=None): + def find_eye(self, roi=[]): raise ValueError('This operation is not supported') - def find_lbp(self, roi=None): + def find_lbp(self, roi=[]): raise ValueError('This operation is not supported') - def find_keypoints(self, roi=None, threshold=20, normalized=False, scale_factor=1.5, max_keypoints=100, corner_detector=CORNER_AGAST): + def find_keypoints(self, roi=[], threshold=20, normalized=False, scale_factor=1.5, max_keypoints=100, corner_detector=CORNER_AGAST): raise ValueError('This operation is not supported') def find_edges(self, edge_type, threshold): - raise ValueError('This operation is not supported') + dst_type = None + if edge_type == EDGE_SIMPLE: + dst_type = image.EdgeDetector.EDGE_SIMPLE + else: + dst_type = image.EdgeDetector.EDGE_CANNY + + img = self.__img.find_edges(dst_type, [], threshold) + img_v1 = Image(do_nothing=True) + img_v1.set_priv_img(img) + + return img_v1 def rgb_to_lab(rgb_tuple): raise ValueError('This operation is not supported') diff --git a/maix/v1/lcd.py b/maix/v1/lcd.py index e48664e..2d858a7 100644 --- a/maix/v1/lcd.py +++ b/maix/v1/lcd.py @@ -46,7 +46,10 @@ def direction(dir): rotation(dir) def mirror(invert): - raise ValueError('This operation is not supported') + __disp.set_hmirror(invert) + +def flip(invert): + __disp.set_vflip(invert) def bgr_to_rgb(enable): raise ValueError('This operation is not supported') @@ -54,4 +57,6 @@ def bgr_to_rgb(enable): def fill_rectangle(x, y, w, h, color): raise ValueError('This operation is not supported') +def set_jb_quality(): + raise ValueError('This operation is not supported\n') diff --git a/maix/v1/sensor.py b/maix/v1/sensor.py index c5a07e9..62a3d5d 100644 --- a/maix/v1/sensor.py +++ b/maix/v1/sensor.py @@ -142,19 +142,21 @@ def get_id(): raise ValueError('This operation is not supported') def set_hmirror(enable): - raise ValueError('This operation is not supported') + __camera.set_vflip(enable) def set_vflip(enable): - raise ValueError('This operation is not supported') + __camera.set_vflip(enable) def set_brightness(brightness): - raise ValueError('This operation is not supported') + brightness = brightness + 3 + val = brightness * 100 / 4 + __camera.set_luma(int(val)) def set_contrast(contrast): - raise ValueError('This operation is not supported') + __camera.set_constrast(contrast) def set_saturation(saturation): - raise ValueError('This operation is not supported') + __camera.set_saturation(saturation) def width(): return __camera.width() @@ -178,7 +180,7 @@ def __read_reg(addr): return __camera.read_reg(addr) def set_jb_quality(): - raise ValueError('This operation is not supported') + raise ValueError('This operation is not supported\n')