logo

移植了openmv的识别矩形的例程,稍加修改,结果报错内存不足,请问该如何解决,附详细代码加openmv型号

2024-10-14 22:17
O
_12pu
4e06495f-d525-4024-a670-fb5a9239cc03.png
e90d980a-879b-4dfa-b55a-5354b167e0fb.jpg

import sensor, image, time

# Initialize the camera

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time=2000)

width = sensor.width()

height = sensor.height()

# Calculate the coordinates of the center ROI

# Threshold for rectangular shape

threshold = ((42, 96, -31, 12, -20, 20))

def find_max(blobs):

max_size=0

for blob in blobs:

if blob[2]*blob[3] > max_size :

max_blob=blob

max_size = blob[2]*blob[3]

return max_blob

while True:

clock = time.clock()

clock.tick()

# Capture a snapshot from the camera

img = sensor.snapshot()

img.lens_corr(strength=1.8, zoom=1.0)

# Find blobs that match the rectangular shape

blobs = img.find_blobs([threshold], pixels_threshold=200, area_threshold=300, merge=True)

max_blob=find_max(blobs)

if max_blob:

for r in img.find_rects(threshold = 10000):

img.draw_rectangle(r.rect(), color = (255, 0, 0))

# Get the four corners' coordinates of the detected shape

x, y, w, h = r.rect()

x1, y1 = x, y

x2, y2 = x + w, y

x3, y3 = x, y + h

x4, y4 = x + w, y + h

# Draw the four corners as crosses

img.draw_cross(x1, y1, color=(255, 0, 0))

img.draw_cross(x2, y2, color=(255, 0, 0))

img.draw_cross(x3, y3, color=(255, 0, 0))

img.draw_cross(x4, y4, color=(255, 0, 0))

# Print the coordinates

print("Corner 1: ({}, {})".format(x1, y1))

print("Corner 2: ({}, {})".format(x2, y2))

print("Corner 3: ({}, {})".format(x3, y3))

print("Corner 4: ({}, {})".format(x4, y4))

2024-10-22 19:59
I
网红小智智 星瞳科技

放弃吧,不要用OpenMV2 M4了。已经停产好多年啦。