Single Camera access by two process at the same time.

asked 2017-10-23 21:02:36 -0500

AK_Tech gravatar image

I want use One Camera for two process/thread e.g. a) live streaming and b) image processing at the same time. Use Case: Application which can handle multiple request based on user request. a) Use can request – Detect cam-1 and do Live streamlining b) Later user can request – Detect Motion/Image processing using same cam-1, while process (a) is doing live streaming. Challenge I see to access same camera by 2 different process at the same time, is there way to reroute the data/pointers of Cam data to different process ?? Any help will be appreciated !! Regards, AK

edit retag flag offensive close merge delete

Comments

1

What have you already try ? Do you use C++ python Java ? Please improve your question

LBerger gravatar imageLBerger ( 2017-10-24 02:18:06 -0500 )edit

Am using C++

AK_Tech gravatar imageAK_Tech ( 2017-10-24 07:19:56 -0500 )edit
1

why do you think, you need 2 seperate processes for this ? (maybe your design, is just wrong.)

berak gravatar imageberak ( 2017-10-24 12:11:53 -0500 )edit

Thanks, Now i tried to achieve using one Process but POC is not helping me.. Below problem I am seeing .. a) thread t1 does not work with Detach, means it does not show the Live streaming b) if I use t1.join() then control will not return to parent process..

using namespace cv;
using namespace std;
//
void func1(VideoCapture cap)
{
    //unconditional loop
    while (true) {
        Mat cam1;
        cap.read(cam1);
        imshow("cam1", cam1);

        if (waitKey(30) >= 0)
            break;

    }
}
void func2(VideoCapture cap)
{
    // place holder will do some processing. 
}
int main() {

    VideoCapture cap(1);   
    if (!cap.isOpened()) { //check if video device has been initialised
        cout << "cannot open camera";
    }
AK_Tech gravatar imageAK_Tech ( 2017-10-26 00:27:29 -0500 )edit

no, it's much simpler:

VideoCapture cap(1);
while(1) {
    Mat frame;
    cap >> frame;

    func1(frame);
    func2(frame);
    func3(frame);
}
berak gravatar imageberak ( 2017-10-26 01:48:43 -0500 )edit