我正在做一个项目,我将让一个摄像头使用Canny边缘检测来检测物体的边缘。然而,对于这个项目,我必须使黑色背景(见图)透明,在相机的原始黑白画面上播放。我该怎么办?注意:在黑暗中
black and white shot of a calendar(left), canny(right)
下面是我使用的代码
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(True):
#Captures video, frame-by-frame
_, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blurred_frame = cv2.GaussianBlur(frame, (5,5),0)
canny1 = cv2.Canny(blurred_frame, 15, 20)
#Displays the output.
cv2.imshow("Frame", frame)
cv2.imshow("Canny1", canny1)
#Press Q to stop loop, then proceed to end program as shown below.
key = cv2.waitKey(1)
if key == ord('q'):
break
#End Program
cap.release()
cv2.destroyAllWindows()
提前谢谢
相关问题 更多 >
编程相关推荐