OLEERM
OLEERM

Reputation: 53

Opencv and Gstreamer

i'm trying to send opencv video cv2.VideoCapture() bash code work excelent, but when I copy it to appsrc it don't want to work

bash:

send `gst-launch-1.0 -v v4l2src device='/dev/video0' ! video/x-raw,width=640,height=480,framerate=30/1,encoding-name=JPEG! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000`

recv `gst-launch-1.0 -v udpsrc port=5000 ! "application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)JPEG" ! rtpjpegdepay ! jpegdec ! videorate ! autovideosink sync=false

python code:

import cv2

cap = cv2.VideoCapture(0)

four = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter()
out.open("appsrc ! video/x-raw,width=640,height=480,framerate=30/1,encoding-name=JPEG! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000",four,30.0,(640,480))

if(out.isOpened()):
    print('d')
while True:
    ret, frame = cap.read()
    if ret:
        out.write(frame)

Upvotes: 2

Views: 2283

Answers (1)

Alper Kucukkomurler
Alper Kucukkomurler

Reputation: 1794

The change occurs because of the data format. Your camera seems to capture images in JPEG format. However OpenCv matrices are raw BGR images, and VideoCapture element converts the jpeg images from camera to raw BGR OpenCv matrices.

There are two changes needed:

  • You need to pass 0 as your fourcc.
  • Your caps video/x-raw,width=640,height=480,framerate=30/1,encoding-name=JPEG will fail to link since your appsrc is raw BGR image. You need to remove encoding-name parameter from the caps. New caps will be: video/x-raw,width=640,height=480,framerate=30/1.

Upvotes: 2

Related Questions