share usb device with videocapture

asked 2015-06-17 11:30:22 -0600

LBerger gravatar image

updated 2015-06-17 11:51:55 -0600

Hi,

On windows with opencv 3.0 I can share same webcam device using VideoCapture. Is it true on linux, android...?

thanks for yours anwers.

int main(int argc, char** argv)
{
        VideoCapture vid1;
        vid1.open(0); // Open device 0 
        VideoCapture vid2;
        vid2.open(0); // Open device 0
        Mat frame1;
        Mat frame2;
        for (;;) {
            vid1 >> frame1;
            vid2 >> frame2;
            if (frame1.empty())
                break;
            if (frame2.empty())
                break;

            imshow("video1", frame1);// Capture with device 0
            imshow("video2", frame2);// Capture with device 0
            imshow("diff", frame2-frame1);// It's not same frame on windows
            char key = (char)waitKey(30);
        }

    }
edit retag flag offensive close merge delete

Comments

i belive there is no difference if we change your code vid1 >> frame2; instead of vid2 >> frame2;

sturkmen gravatar imagesturkmen ( 2015-07-14 11:14:34 -0600 )edit

I don't think so because >> means Grabs, decodes and returns the next video frame. PS have you try my software?

LBerger gravatar imageLBerger ( 2015-07-14 14:30:48 -0600 )edit

maybe this time i will explain myself

int main(int argc, char** argv)

        .
        .
        .
        Mat frame1;
        Mat frame2;
        for (;;) {
           vid1 >> frame1;
           vid1 >> frame2;  // i replaced vid2 & vid1 at this line, would anything change ?? IMHO no!
            .
            .
            .
sturkmen gravatar imagesturkmen ( 2015-07-14 17:01:27 -0600 )edit

No results are similar. As I write s "Grabs, decodes and returns the next video frame" this is relative to real driver. On my PC I 've got only one webcam so vid1and vid2 bind to same driver and for this driver there is only one next frame.

LBerger gravatar imageLBerger ( 2015-07-15 02:55:05 -0600 )edit
1

@berak Is it really normal behaviour ?

>> p= cv.VideoCapture(0)
>>> p.isOpened()
True
>>> p1=cv.VideoCapture(0)
>>> p1.isOpened()
True

If I run two python instance I can opened stream 0 but I cannot read it:

 WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772
[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772
LBerger gravatar imageLBerger ( 2019-01-17 07:29:55 -0600 )edit
1

i get the same (also from c++)

but it shouldn't be ! (imho)

reading 2nd cam with CAP_MSMF also fails here (but succeeds with CAP_DSHOW)

berak gravatar imageberak ( 2019-01-17 07:39:07 -0600 )edit

now I tried video.py 0 and video.py 700 It works ! but video.py 700 twice gives an error AttributeError: 'NoneType' object has no attribute 'read'

LBerger gravatar imageLBerger ( 2019-01-17 07:50:49 -0600 )edit