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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.