logo

摄像头运行过程中,画面卡顿怎么解决?希望摄像头在供电的情况下一直识别颜色

2024-05-10 19:33
9
gqmf
import sensor, image, time
from pyb import Pin
import math
threshold_index = 0
thresholds = [
	(34, 82, -32, -12, -13, 31),
]
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock = time.clock()
pin0 = Pin("P0", Pin.OUT_PP, Pin.PULL_NONE)
pin1 = Pin("P1", Pin.OUT_PP, Pin.PULL_NONE)
LED1 = Pin("P2", Pin.OUT_PP, Pin.PULL_NONE)
LED2 = Pin("P3", Pin.OUT_PP, Pin.PULL_NONE)
while True:
	clock.tick()
	img = sensor.snapshot()
	for blob in img.find_blobs(
			[thresholds[threshold_index]],
			pixels_threshold=200,
			area_threshold=200,
			merge=True,
		):
		if blob.elongation() > 0.5:
			img.draw_edges(blob.min_corners(), color=(255, 0, 0))
			img.draw_line(blob.major_axis_line(), color=(0, 255, 0))
			img.draw_line(blob.minor_axis_line(), color=(0, 0, 255))
			img.draw_rectangle(blob.rect())
			img.draw_cross(blob.cx(), blob.cy())
			img.draw_keypoints(
				[(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20
			)
			pin1.value(1)
			LED1.value(1)
			pin0.value(0)
			LED2.value(0)
			time.sleep(5)
	print(clock.fps())
	pin1.value(0)
	LED1.value(0)
	pin0.value(1)
	LED2.value(1)
	time.sleep(5)
2024-05-13 20:06
I
网红小智智 星瞳科技

把41行和47行的sleep删除就不卡了。