我正在用python编写一个程序,使用OpenCV从我的网络摄像头记录的视频中检测边缘(Canny边缘检测器)。我还使用了两个轨迹条来控制阈值(以便了解这些值如何改变边缘检测器的输出)。在
我写的代码如下:
import cv2
import numpy as np
def nothing(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('cannyEdge')
cv2.createTrackbar("minVal", "cannyEdge", 0,100, nothing)
cv2.createTrackbar("maxVal", "cannyEdge", 100,200,nothing)
cap = cv2.VideoCapture(0)
while(True):
minVal = cv2.getTrackbarPos("minVal", "cannyEdge")
maxVal = cv2.getTrackbarPos("maxVal", "cannyEdge")
#capture frame by frame
ret, frame = cap.read()
cv2.imshow('frame', frame)
edge = cv2.Canny(frame,minVal,maxVal)
#display the resulting frame
cv2.imshow('frame', edge)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#When everything is done, release the capture
cap.release
cv2.destroyAllWindows()
这个程序只是为了教育目的,因为我目前正在学习使用OpenCV。在
每次我运行上面的程序时,代码似乎运行得很好,但我得到以下错误:
GLib GObject CRITICAL**:g_object_unref:断言“g_IS_object(object)”失败
我搜索了这个错误发生的原因,但没有找到任何有用的东西。我的直觉告诉我,我的轨迹条实现是错误的,因此它导致了这个错误。在
我使用的教程如下:
有人知道这个错误发生的原因吗?任何帮助都将不胜感激!在
我运行的是ubuntu14.04、opencv3.2.0和python2.7.6
你有没有创建另一个名为“frame”的窗口?如果不是,看起来应该将“frame”更改为“cannyEdge”:
尝试制作轨迹条并在同一窗口中显示图像,看看错误是否仍然存在。我打赌不应该。更改:cv2.imshow('cannyEdge',edge)
相关问题 更多 >
编程相关推荐