Skip to content

Commit

Permalink
* support for maixpy-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Apr 15, 2024
1 parent 9a12337 commit 942d653
Show file tree
Hide file tree
Showing 42 changed files with 1,474 additions and 610 deletions.
37 changes: 37 additions & 0 deletions examples/maixpy_v1/image/add_sub_mul_div.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions examples/maixpy_v1/image/bilateral.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions examples/maixpy_v1/image/binary.py
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions examples/maixpy_v1/image/bit_operation.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions examples/maixpy_v1/image/blend.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions examples/maixpy_v1/image/difference.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions examples/maixpy_v1/image/draw.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions examples/maixpy_v1/image/erode.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions examples/maixpy_v1/image/find_barcodes.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 942d653

Please sign in to comment.