I'm coding in python and using my webcam for now on testing.
(ASUS KV55J | Ubuntu 14.04 | python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] | OpenCV version '2.4.8')
I can successfully show the image from my webcam (very simple code) but when I try to set a mouse callback to when mouse passes over the image (also a very simple code) there are a big issue, a Segmentation fault after several frames (takes about 10/20seconds to fail but if i comment the callback it will work until "Ctrl-c" pressed).
Does anyone know why it happens?
I ran this and got this error (even if i dont move the mouse or press anything):
ncc@ncc-K55VJ:~/Desktop/testes_python/gui$ python a_teste_capture.py
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
Left mouse button pushed
Left mouse button pushed
Left mouse button pushed
Left mouse button pushed
Left mouse button pushed
Segmentation fault (core dumped)
The simplest code I had at the beggining was:
import cv, cv2
def click_and_take_frame(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
print 'Left mouse button pushed'
def main_function():
camera_device=cv2.VideoCapture(0)
frame_name="Segmentation fault (core dumped) TEST WINDOW"
cv2.namedWindow(frame_name, cv2.WINDOW_AUTOSIZE)
while 1:
(grabbed1, frame1) = camera_device.read()
frame1= cv2.cvtColor(frame1, cv2.CV_8U)
cv2.imshow(frame_name, frame1)
cv2.setMouseCallback(frame_name, click_and_take_frame)
key = cv2.waitKey(1) & 0xFF
cv2.destroyAllWindows() # Closes displayed windows
if __name__ == '__main__':
import sys
main_function()