C++ 如何关闭摄影机(OpenCv Beaglebone)

C++ 如何关闭摄影机(OpenCv Beaglebone),c++,opencv,camera,beagleboard,C++,Opencv,Camera,Beagleboard,你好 我想知道如何在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 << "Faile

你好

我想知道如何在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;
}

cvQueryFrame

从相机或文件中获取并返回帧

IplImage*cvQueryFrame-CvCapture*capture

捕获视频捕获结构

函数cvQueryFrame从相机或视频文件中获取帧,解压缩并>返回该帧。此函数只是一个>调用中cvGrabFrame和cvRetrieveFrame的组合。用户不应发布或修改返回的图像

同时检查:


我希望这对你有用。祝你好运。

我刚刚不得不做camera.release。但是谢谢你的详细回复!