【问题标题】:How to close camera (OpenCv Beaglebone)如何关闭相机(OpenCv Beaglebone)
【发布时间】:2014-03-25 06:45:43
【问题描述】:

美好的一天,

我想弄清楚如何在 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循环结束时,我想关闭相机,但当然它仍然保持打开状态

【问题讨论】:

    标签: c++ opencv camera beagleboard


    【解决方案1】:

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

    从 opencv 文档检查这个例子:

    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* 捕获);

    捕获视频捕获结构。

    函数 cvQueryFrame 从相机或视频文件中抓取一帧,解压缩并 > 返回它。这个函数只是 cvGrabFrame 和 cvRetrieveFrame 在一个 > 调用中的组合。 用户不得发布或修改返回的图片。

    同时检查:http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/

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

    【讨论】:

    • 我只需要执行 camera.release()。但是谢谢你的详细回复!
    猜你喜欢
    • 2023-02-04
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    • 2020-01-25
    • 1970-01-01
    • 2020-05-16
    相关资源
    最近更新 更多