Ask Your Question

Sam94's profile - activity

2016-09-16 17:09:12 -0500 commented answer Segmentation fault OpenCV cap.read() udp stream Python

My OpenCV is built with GStreamer enabled. I added the cv2.CAP_GSTREAMER as suggested, but it's still throwing the same error. What do you think might be wrong with the URL? It works in gstreamer, so I would think that it would work here too. I did test "udpsrc uri=udp://0.0.0.0:5600" but it still has the same error.

2016-09-15 10:47:01 -0500 commented question Segmentation fault OpenCV cap.read() udp stream Python

Thanks but that didn't fix it, still the same error. I updated the code to reflect the changes.

2016-09-15 10:46:25 -0500 received badge  Editor (source)
2016-09-15 10:35:59 -0500 asked a question Segmentation fault OpenCV cap.read() udp stream Python

I'm new to using OpenCV, and I'm trying to write a program to access a video stream on a UDP port. However, the code keeps giving a segmentation fault when I run it. The program is just intended to display each frame as it is read in by OpenCV, and it works on files on my computer. If you could point out what I'm doing wrong, I would appreciate it.

import cv2
import numpy as np

cap = cv2.VideoCapture("udpsrc port=5600 caps=\"application/x-rtp, format=(string)I420, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, framerate=(fraction)25/1\" ! rtph264depay !  decodebin ! appsink", cv2.CAP_GSTREAMER)

while(cap.isOpened()):
    print "loop"

    ret, frame = cap.read()
    print "ret, frame"

    if frame == None:
        break
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    print "gray"

    cv2.imshow('frame', gray)
    print "imshow"
    if cv2.waitKey(40) & 0xFF == ord('q'):
        print "breaking"
        break

cap.release()
cv2.destroyAllWindows()

The output is:

loop ret, frame gray imshow loop Segmentation fault (core dumped)

Running:

gst-launch-1.0 -e udpsrc port=5600 caps="application/x-rtp, format=(string)I420, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, framerate=(fraction)25/1" ! rtph264depay !  decodebin ! avimux ! filesink location=/home/lab/Desktop/test.avi

in the terminal works just fine, so I'm not sure what to look at next.

Thanks for your help.