如何关闭相机(OpenCv Beaglebone)

How to close camera (OpenCv Beaglebone)

本文关键字:Beaglebone OpenCv 何关闭 相机      更新时间:2023-10-16

大家好,

我正试图找出如何关闭相机上的小猎犬在openCV。我尝试了许多命令,如释放(&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循环结束时,我想关闭相机,但它仍然是打开的

摄像机将在videoccapture析构函数中自动取消初始化。

查看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在一个>呼叫返回的图像不允许用户发布或修改。

也可以查看:http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/

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