logo

请教:灰度转换为模拟信号输出

2021-04-05 21:12
V
_36hw
import sensor, image, time, pyb
from pyb import DAC
from pyb import LED
import json
Para = {};
with open("./config.json", 'r', encoding='utf-8') as json_file:
	Para = json.load(json_file)
	print(Para)
roi = (120, 50, 80, 60)				#有效区域L
dac = DAC(pyb.Pin("P6"), bits=8)
sensor.reset()		#重置并初始化传感器。
if Para["workmode"]==0:
	sensor.set_pixformat(sensor.GRAYSCALE)		  #如果MODE=0将像素格式设置为GREYSCALE(灰度)
else:
	sensor.set_pixformat(sensor.RGB565)		  #将像素格式设置为RGB565
sensor.set_framesize(sensor.QVGA)			#将帧大小设置为QVGA(320x240)			
sensor.set_windowing(roi)				#获取有效图像区域
sensor.set_brightness(0)				#亮度
sensor.set_auto_exposure(False, Para["exposuretime"]);
sensor.set_auto_gain(False, Para["autogain"])
sensor.set_auto_whitebal(False, rgb_gain_db = (Para["wb_Rgain"], Para["wb_Ggain"], Para["wb_Bgain"]))
sensor.skip_frames(time = 2000)	  #等待设置生效。
clock = time.clock()			#创建一个时钟对象来跟踪FPS。
tH = Para["thresholdHigh"]*255.0/100.0;
tL = Para["thresholdLow"]*255.0/100.0
mA_4 = 31
mA_4_20 = 123.636
while(True):
	clock.tick()		#更新FPS时钟。
	img = sensor.snapshot()	#拍照并返回图像。
	para = img.get_statistics()	#PARA=图像信息集合
	avrg = para.mean()		#avrg=滤波(模糊处理)
	if avrg>=tL and tH>tL:
		temp =(avrg-tL)*mA_4_20/(tH-tL)+mA_4
	else:
		temp = 23
	if temp<185.45 and temp>20:
		print("Out = %d" %temp)
		dac.write(int(temp))
e1afc671-994c-4e29-9e6b-f6a6aea45ce8.png

写入以前模块的代码,运行不了是什么原因啊?

2021-04-05 21:25
V
_36hw

补充:以前用的是OpenMV4,这次是采购的OpenMV-H7,代码需要更改吗?

2021-04-06 14:44
I
网红小智智 星瞳科技

第10行明显括号不匹配。

I
网红小智智 星瞳科技

OpenMV4 就是OpenMV H7