完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
1.识别长度 # Untitled - By: YU - 周三 4月 7 2021 import sensor, image, time, ustruct from pyb import UART #导入串口 sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) clock = time.clock() K=0.16 #实际直径=K*直径像素 故:K=4CM/25PIX aim_threshold =(24, 80, 47, 72, -44, 106) #L A B uart = UART(3,115200) #OpenMV上P4,P5对应的串口3 第二个参数是波特率 uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters #def sending_data(a): #global uart; ##frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B]; ##data = bytearray(frame) #data = ustruct.pack(" #0x12, #帧头2 #int(a), #数据1 #0x5B) #uart.write(data); #必须要传入一个字节数组 while(True): clock.tick() img = sensor.snapshot() # print(clock.fps()) blobs = img.find_blobs([aim_threshold]) if len(blobs)==1: b=blobs[0] img.draw_rectangle(b[0:4]) img.draw_cross(b[5],b[6]) lm=(b[2]+b[3])/2 length=K*lm print("管长:",length) length=int(length) data = bytearray([11,22,length,33]) uart.write(data) #pack各字母对应类型 #x pad byte no value 1 #c char string of length 1 1 #b signed char integer 1 #B unsigned char integer 1 #? _Bool bool 1 #h short integer 2 #H unsigned short integer 2 #i int integer 4 #I unsigned int integer or long 4 #l long integer 4 #L unsigned long long 4 #q long long long 8 #Q unsilong long long 8 #f float float 4 #d double float 8 #s char[] string 1 #p char[] string 1 #P void * long 2.识别面积 # Untitled - By: YU - 周三 4月 7 2021 import sensor, image, time, ustruct from pyb import UART #导入串口 sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) clock = time.clock() K=0.16 #实际直径=K*直径像素 故:K=4CM/25PIX aim_threshold =(24, 80, 47, 72, -44, 106) #L A B uart = UART(3,115200) #OpenMV上P4,P5对应的串口3 第二个参数是波特率 uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters while(True): clock.tick() img = sensor.snapshot() #print(clock.fps()) blobs = img.find_blobs([aim_threshold]) if len(blobs)==1: b=blobs[0] img.draw_rectangle(b[0:4]) img.draw_cross(b[5],b[6]) area=b.pixels() print("面积:",area) qian=area//100 shi=area%100 data = bytearray([11,22,qian,shi,33]) uart.write(data) STM32 一定要共地(浪费了一个晚上的教训) 1.识别长度 /* USER CODE BEGIN PTD */ uint8_t re_buf1; //缓冲区 uint8_t openmvdata=0; //长度 整数 uint8_t state=0; /* USER CODE END PTD */ /* USER CODE BEGIN PM */ void OpmvDataGet(uint8_t data) { if(state==0 && data ==11) //帧头1 { //printf("state=1 data:%d",data); state =1 ; } else if (state==1 && data == 22) //帧头2 { //printf("state=2 data:%d",data); state=2; } else if(state == 2) { //printf("state=3 data:%d",data); state=3; openmvdata=data; } else if(state ==3) { if(data ==33) //帧尾 { printf("长度:%d",openmvdata); state=0; } else { openmvdata=0; state=0; } } } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) //opmv-receive { if(huart == &huart1) { HAL_UART_Receive_IT(&huart1,&re_buf1,1); OpmvDataGet(re_buf1); } } /* USER CODE END PM */ int main(void) { /* USER CODE BEGIN 2 */ printf("stm32初始化"); HAL_UART_Receive_IT(&huart1,&re_buf1,1); /* USER CODE END 2 */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } } 2.识别面积 void OpmvDataGet(uint8_t data) { if(state==0 && data ==11) //帧头1 { //printf("state=1 data:%d",data); state =1 ; } else if (state==1 && data == 22) //帧头2 { //printf("state=2 data:%d",data); state=2; } else if(state == 2) { //printf("state=3 data:%d",data); state=3; openmvdata_1=data; //assic转为int } else if(state == 3) { //printf("state=3 data:%d",data); state=4; openmvdata_2=data; //assic转为int //printf("openmvdata_1:%c",openmvdata_1); //printf("openmvdata_2:%c",openmvdata_2); openmvdata=openmvdata_1*100+openmvdata_2; } else if(state ==4) { if(data ==33) //帧尾 { printf("面积:%d",openmvdata); state=0; } else { openmvdata_1=0; openmvdata_2=0; state=0; } } } 串口接收到的字符型数据转化成数字: k = USART_RXBuff[3]-0x30;1或者: k = USART_RXBuff[3]-'0'; |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1548 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1493 浏览 1 评论
915 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
656 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1544 浏览 2 评论
1845浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
598浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
499浏览 3评论
502浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
483浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-6 07:26 , Processed in 0.644980 second(s), Total 47, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号