c++ - 如何关闭相机(OpenCv Beaglebone)

标签 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 << "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 文档中查看此示例:

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

Grabs and returns a frame from camera or file

IplImage* cvQueryFrame( CvCapture* capture );

capture video capturing structure.

The function cvQueryFrame grabs a frame from camera or video file, decompresses and > returns it. This function is just a combination of cvGrabFrame and cvRetrieveFrame in one > call. The returned image should not be released or modified by user.

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

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

关于c++ - 如何关闭相机(OpenCv Beaglebone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627210/

相关文章:

python - 查找图像中颜色方 block 的轮廓和中点

python - 在OSX Yosemite上为Python 2.7安装OpenCV时出错-错误:无匹配功能

opencv - opencv中的3d到2d转换

c++ - 用于多线程 Linux 应用程序的信号样式 IPC

c++ - 使用 ifstream 读取 float

c++ - 获取系统TEMP变量的路径

c++ - gdb 奇怪的行为( [next] 在 block 代码上跳回几行)

android - 在 OpenCV Android 或 Java 中设置 SURF 算法参数

android - Galaxy S3 - 以纵向模式拍照会破坏 Activity

iphone - 如何只允许 iPhone 4 使用应用程序,因为它使用前置摄像头