0

I used this example to record a video, but there is no output. Any help, please:

import cv2 if __ name __ == " __ main __ ": # find the webcam capture = cv2.VideoCapture(0) # video recorder fourcc = cv2.cv.CV_FOURCC(*'XVID') # cv2.VideoWriter_fourcc() does not exist videoOut = cv2.VideoWriter("output.avi", fourcc, 20.0, (640, 480)) # record video while (capture.isOpened()): ret, frame = capture.read() if ret: videoOut.write(frame) cv2.imshow('Video Stream', frame) else: break # Tiny Pause key = cv2.waitKey(1) capture.release() videoOut.release() cv2.destroyAllWindows() 

I got this error:

HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP (Video Stream:2758): Gtk-WARNING **: cannot open display: 

1 Answer 1

1

You're trying to run it in headless mode. A bug/feature of some OpenCV things is that it's a must-have requirement to be run from Xterm of already working X11/GUI. Weird, but the root of the problem is that it uses some external components like video codecs in your case via GUI-related component HighUI. If you have a working and running X11/GUI but still have this error - make sure to set the environment variable DISPLAY to your X11 display and after setting it via export command, run your program like DISPLAY=xx:yy your_binary via env importing on-exec.

13
  • I tried it with a HDMI cable but I got the same error Commented May 6, 2016 at 21:36
  • @happy from GUI Xterm? Commented May 6, 2016 at 21:40
  • no,but normally with hdmi we can display it no?? Commented May 6, 2016 at 21:44
  • @happy if you haven't exported a DISPLAY variable - no, a headless call is headless literally Commented May 6, 2016 at 21:45
  • haw can I exported it ??? Commented May 6, 2016 at 21:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.