Tinker board 使用摄像头跳转:https://blog.csdn.net/chenjambo/article/details/125928360
安装 OpenCV
$ pip3 install pip --upgrade
$ pip3 install opencv-python --user
导入 cv2 ,并输出版本以验证是否安装成功
$ python3 -c "import cv2; print(cv2.__version__)"
4.6.0
测试
新建 cv_transforms.py
文件,编辑以下内容。此脚本会使用摄像头并打开四个窗口,分别显示摄像头的原画面,和经过处理后的降画质、灰阶、边缘检测。
#!/usr/bin/python3
import cv2
import numpy as np
# capCamera = cv2.VideoCapture(0) # CSI camera default index
capCamera = cv2.VideoCapture(5) # USB camera default index
windowName = "cv transforms"
while capCamera.isOpened():
isRead, frame = capCamera.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(hsv, (7, 7), 1.5)
edges = cv2.Canny(blur, 0, 40)
dispFrame = cv2.resize(frame, (640, 360))
dispHsv = cv2.resize(hsv, (640, 360))
dispBlur = cv2.resize(blur, (640, 360))
dispEdges = cv2.resize(edges, (640, 360))
dispLine1 = np.concatenate(
(dispFrame, cv2.cvtColor(dispEdges, cv2.COLOR_GRAY2BGR)), axis=1
)
dispLine2 = np.concatenate(
(
cv2.cvtColor(dispHsv, cv2.COLOR_GRAY2BGR),
cv2.cvtColor(dispBlur, cv2.COLOR_GRAY2BGR),
),
axis=1,
)
dispAll = np.concatenate((dispLine1, dispLine2), axis=0)
cv2.imshow(windowName, dispAll)
if cv2.waitKey(10) == 27:
break
camera.release()
cv2.destroyAllWindows()
用 python3 启动脚本
python3 cv_transforms.py