Ask Your Question

Revision history [back]

How to use more than two cameras?

How to use more than two cameras?

image description

I tried on with C++, on Java, result one. More than two cameras bug. I try to just save images from the camera to a folder.

How to use more than two cameras?

How to use more than two cameras?

image description

I tried on with C++, on Java, result one. More than two cameras bug. I try to just save images from the camera to a folder.

enter code here

void CameraThread(int id) {

int sensivity = 30;
double maxArea = 30;

int widthFrame = 320;
int heightFrame = 160;

// для работы со списком камер
Mat *frameI = new Mat(heightFrame, widthFrame, CV_8UC3);
Mat *frameCurrentI = new Mat(heightFrame, widthFrame, CV_8UC3);
Mat *framePreviousI = new Mat(heightFrame, widthFrame, CV_8UC3);
Mat *frameResultI = new Mat(heightFrame, widthFrame, CV_8UC3);


Size *size = new Size(3, 3);
Mat *v = new Mat();

// open camera
std::cout << "thread camera id " << id << std::endl;

VideoCapture cap(id);

cap.set(CAP_PROP_FRAME_WIDTH, widthFrame);
cap.set(CAP_PROP_FRAME_HEIGHT, heightFrame);


std::string filename; 
filename.append("camera_");
filename.append(std::to_string(id));
filename.append(".jpg");

Mat frame;

while (true) {

    if (!cap.grab()) {
        printf("failed to grab from camera\n");
    }
    else
    {
        cap.read(frame);

        if (frame.empty()) {
            printf("failed to grab from camera\n");
        }
        else {
            imwrite(filename, frame);
        }
    }

    /*if (cap.read(frame)) {
        m.lock();
        cap >> frame;
        imwrite(filename, frame);
        m.unlock();
    } */

    //Sleep(1000);

}

}

int main() { std::thread t0(CameraThread, 2); t0.detach();

std::thread t1(CameraThread, 1);
t1.detach();

std::thread t2(CameraThread, 2);
t2.detach();

std::thread t3(CameraThread, 3);
t3.detach();

std::thread t4(CameraThread, 4);
t4.detach();

std::thread t5(CameraThread, 5);
t5.detach();

std::thread t6(CameraThread, 6);
t6.join();

waitKey();
return 0;

}

How to use more than two cameras?

How to use more than two cameras?

image descriptionimage description

I tried on with C++, on Java, result one. More than two cameras bug. I try to just save images from the camera to a folder.

enter code here

void CameraThread(int id) {

{

    int sensivity = 30;
 double maxArea = 30;

 int widthFrame = 320;
 int heightFrame = 160;

 // для работы со списком камер
 Mat *frameI = new Mat(heightFrame, widthFrame, CV_8UC3);
 Mat *frameCurrentI = new Mat(heightFrame, widthFrame, CV_8UC3);
 Mat *framePreviousI = new Mat(heightFrame, widthFrame, CV_8UC3);
 Mat *frameResultI = new Mat(heightFrame, widthFrame, CV_8UC3);


 Size *size = new Size(3, 3);
 Mat *v = new Mat();

 // open camera
 std::cout << "thread camera id " << id << std::endl;

 VideoCapture cap(id);

 cap.set(CAP_PROP_FRAME_WIDTH, widthFrame);
 cap.set(CAP_PROP_FRAME_HEIGHT, heightFrame);


 std::string filename; 
 filename.append("camera_");
 filename.append(std::to_string(id));
 filename.append(".jpg");

 Mat frame;

 while (true) {

     if (!cap.grab()) {
         printf("failed to grab from camera\n");
     }
     else
    {
    {
            cap.read(frame);

         if (frame.empty()) {
             printf("failed to grab from camera\n");
         }
         else {
             imwrite(filename, frame);
         }
     }

     /*if (cap.read(frame)) {
         m.lock();
         cap >> frame;
         imwrite(filename, frame);
         m.unlock();
     } */

     //Sleep(1000);

    }
}

int main()
{
    std::thread t0(CameraThread, 2);
    t0.detach();

    std::thread t1(CameraThread, 1);
    t1.detach();

    std::thread t2(CameraThread, 2);
    t2.detach();

    std::thread t3(CameraThread, 3);
    t3.detach();

    std::thread t4(CameraThread, 4);
    t4.detach();

    std::thread t5(CameraThread, 5);
    t5.detach();

    std::thread t6(CameraThread, 6);
    t6.join();

    waitKey();
    return 0;
}

}

int main() { std::thread t0(CameraThread, 2); t0.detach();

std::thread t1(CameraThread, 1);
t1.detach();

std::thread t2(CameraThread, 2);
t2.detach();

std::thread t3(CameraThread, 3);
t3.detach();

std::thread t4(CameraThread, 4);
t4.detach();

std::thread t5(CameraThread, 5);
t5.detach();

std::thread t6(CameraThread, 6);
t6.join();

waitKey();
return 0;

}