美好的一天,

我试图弄清楚如何在openCV中关闭beaglebone上的相机。我已经尝试了许多命令,例如release(&camera),但都不存在,并且当我不想使用它时,相机会继续保持打开状态。

VideoCapture capture(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH,320);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,240);
if(!capture.isOpened()){
     cout << "Failed to connect to the camera." << endl;
}
Mat frame, edges, cont;

while(1){
    cout<<sending<<endl;
    if(sending){
        for(int i=0; i<frames; i++){
            capture >> frame;
            if(frame.empty()){
            cout << "Failed to capture an image" << endl;
            return 0;
            }
            cvtColor(frame, edges, CV_BGR2GRAY);

代码是这样的,在for循环的最后,我想关闭相机,但是当然它仍然保持打开状态

最佳答案

摄像机将在VideoCapture析构函数中自动取消初始化。
从opencv docu中检查以下示例:

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}


还要检查:http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/
希望这对您有用。祝你好运。

10-08 06:56