Skip to content

Commit

Permalink
* add more image examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed May 13, 2024
1 parent 15e4b7a commit d2ad2d9
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/vision/image_basic/binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from maix import image

# 1. load image
src_img = image.load("test.jpg")

# 2. binarize the image
thresholds = ((0, 100, 20, 80, 10, 80))
img = src_img.copy()
img.binary(thresholds)
img.save("binary.jpg")
18 changes: 18 additions & 0 deletions examples/vision/image_basic/find_apriltags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from maix import camera, display, image
from maix.image import ApriltagFamilies

cam = camera.Camera(160, 120)
disp = display.Display()

families = ApriltagFamilies.TAG36H11

while 1:
img = cam.read()

apriltags = img.find_apriltags(families=ApriltagFamilies.TAG36H11)
for a in apriltags:
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], image.COLOR_GREEN, 2)

disp.show(img)
16 changes: 16 additions & 0 deletions examples/vision/image_basic/find_barcodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from maix import camera, display, image

cam = camera.Camera(320, 240)
disp = display.Display()


while 1:
img = cam.read()

barcodes = img.find_barcodes()
for b in barcodes:
rect = b.rect()
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)

disp.show(img)
20 changes: 20 additions & 0 deletions examples/vision/image_basic/find_blobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from maix import camera, display, image

cam = camera.Camera(320, 240)
disp = display.Display()

area_threshold = 1000
pixels_threshold = 1000
# thresholds = [[0, 80, 40, 80, 10, 80]] # red
thresholds = [[0, 80, -120, -10, 0, 30]] # green
# thresholds = [[0, 80, 30, 100, -120, -60]] # blue
while 1:
img = cam.read()

blobs = img.find_blobs(thresholds, area_threshold = 1000, pixels_threshold = 1000)
for b in blobs:
corners = b.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], image.COLOR_RED)

disp.show(img)
12 changes: 12 additions & 0 deletions examples/vision/image_basic/find_edges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from maix import camera, display
from maix.image import EdgeDetector

cam = camera.Camera(320, 240)
disp = display.Display()

edge_type = EdgeDetector.EDGE_CANNY

while 1:
img = cam.read()
img.find_edges(edge_type, threshold=[50, 100])
disp.show(img)
23 changes: 23 additions & 0 deletions examples/vision/image_basic/find_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from maix import camera, display, image
import math

cam = camera.Camera(320, 240)
disp = display.Display()

threshold = 2000

while 1:
img = cam.read()

lines = img.find_lines(threshold=2000)
for a in lines:
img.draw_line(a.x1(), a.y1(), a.x2(), a.y2(), image.COLOR_RED, 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, image.COLOR_GREEN, 2)
img.draw_string(x, y, "theta: " + str(theta) + "," + "rho: " + str(rho), image.COLOR_GREEN)

disp.show(img)
15 changes: 15 additions & 0 deletions examples/vision/image_basic/find_qrcodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from maix import camera, display, image

cam = camera.Camera(320, 240)
disp = display.Display()

while 1:
img = cam.read()
qrcodes = img.find_qrcodes()
for q in qrcodes:
corners = q.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], image.COLOR_RED)
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)

disp.show(img)

0 comments on commit d2ad2d9

Please sign in to comment.