使用:Logitech HD1080p摄像头
NVIDIA jetson的摄像头的配置很方便,甚至内部自带了opencv的库
连接方式有USB和CSI两种,这里用的USB
用Python import一下,没有的话可以用pip install opencv之类的,网上教程很全.
附上一个线段识别的代码让各位测试一下摄像头有没有用
import cv2
import numpy as npdef line_detect_possible_demo(image):gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)edges = cv2.Canny(gray, 50, 150, apertureSize=3) # apertureSize是sobel算子大小,只能为1,3,5,7lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength=50,maxLineGap=10) # 函数将通过步长为1的半径和步长为π/180的角来搜索所有可能的直线if lines is None:return imagefor line in lines:print(type(line)) # 多维数组x1, y1, x2, y2 = line[0]cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)#cv2.imshow("line_detect_possible_demo", image)return imagedef line_detection(image):gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)edges = cv2.Canny(gray, 50, 150, apertureSize=3) # apertureSize是sobel算子大小,只能为1,3,5,7lines = cv2.HoughLines(edges, 1, np.pi / 180, 100) # 函数将通过步长为1的半径和步长为π/180的角来搜索所有可能的直线if lines is None:return imagefor linet in lines:rho, theta = linet[0] # 获取极值ρ长度和θ角度a = np.cos(theta) # 获取角度cos值b = np.sin(theta) # 获取角度sin值x0 = a * rho # 获取x轴值y0 = b * rho # 获取y轴值 x0和y0是直线的中点x1 = int(x0 + 1000 * (-b)) # 获取这条直线最大值点x1y1 = int(y0 + 1000 * (a)) # 获取这条直线最大值点y1x2 = int(x0 - 1000 * (-b)) # 获取这条直线最小值点x2 y2 = int(y0 - 1000 * (a)) # 获取这条直线最小值点y2 其中*1000是内部规则cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2) # 开始划线# cv2.imshow("image line", image)return imagecap = cv2.VideoCapture(0)while True:ret, frame = cap.read()while ret is 0:ret, frame = cap.read()if ret is not 0:breakframe = line_detect_possible_demo(frame)cv2.imshow('frame', frame) # 一个窗口用以显示原视频if cv2.waitKey(1) & 0xFF == ord('q'):breakcap.release()
cv2.destroyAllWindows()