linux上的OpenCv+Gstreamer+python

2024-03-29 12:46:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我告诉他们,我需要用gstreamerhayo实现opencv,而不是如何在管道Gstreamer上使用opencv编写代码。 我们的想法是通过OpenCV获取图像和网络摄像头,并使用GStreamer处理一些过滤器。在

另外,如果我想告诉VideoCapture()从v4l2src device=/dev/video1获取数据,或者无法在v4l2src device=/dev/video0中写入数据(使用linux,我有一个disp虚拟视频,video0) 抛出以下错误

GStreamer:在手动管道中找不到appsink 在函数cvCaptureFromCAM_GStreamer中

import cv2

cv2.namedWindow('webCam')
cap = cv2.VideoCapture(1)  # "v4l2src device=/dev/video1"
# cap.open("img/bg.avi")


if cap.isOpened():
    ret, frame = cap.read()
else:
    ret = False
    print "problema aqui?"


while True:
    #se toma cada frame
    ret,frame = cap.read()
    frame = cv2.flip(frame,1)

    cv2.imshow('webCam', frame)

    width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    # cv2.imwrite("/dev/video0", frame)
    fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
    pathVid = "/dev/video0" # 'img/output2.avi'
    # out = cv2.VideoWriter(pathVid, fourcc, 30, (width,height))
    out = cv2.VideoWriter(pathVid, fourcc, 30, (640,480))
    out.write(frame)
    cv2.VideoWr
    esc = cv2.waitKey(5) & 0xFF == 27
    if esc:
        break

cap.release()
cv2.destroyAllWindows()

Tags: dev管道deviceoutcv2frameopencvcap