Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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")

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

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

    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.

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")

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.

click to hide/show revision 3
retagged

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")

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.

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")
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.