版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_27587443/article/details/72859388
接下来果蔬秤解决的是关于输入的问题,通过摄像头来捕获拍摄的果蔬,这是需要解决的一个问题。
搭配好Python-opencv环境后,写一段python代码进行测试:
- import numpy as np
- import cv2
- img = cv2.imread('askbutton.png', 0)
- cv2.imshow('image', img)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
可以发现成功读取了askbutton这个图片,如下图所示:
接下来开始视频的捕获,python代码如下:
- import numpy as np
- import cv2
- cap = cv2.VideoCapture(0)
- while(True):
- # Capture frame-by-frame
- ret, frame = cap.read()
- # Our operations on the frame come here
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- # Display the resulting frame
- cv2.imshow('frame',gray)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # When everything done, release the capture
- cap.release()
- cv2.destroyAllWindows()
获取的是视频的灰度图,可以以正常的帧率进行捕获,那么程序的输入便成功的获取,输出为向arduino发送的串口数据。那么接下来的核心问题就是关于果蔬种类的识别程序了,用接下来的时间去进行这项工作。
大体的思路为通过深度学习训练好模型,然后提取出测试样本的特征,把这些特征通过分类器进行分类,进行到这里,就是一个相对简单的分类(classification)问题了。