首页 文章

为什么我在BeagleBone Black上的OpenCV程序会捕获这样的图像?

提问于
浏览
0

这是我的程序生成的图像类型的链接:http://imgur.com/a/vibBx#0

我正在尝试一个我写过的简单的捕获测试程序 . 我试图在循环中捕获图像并将它们保存到正确编号的板上 . 第一次捕获有时会被破坏,随后的捕获是两个图像的混合 . 我还观察到,有时图像的上半部分来自上一次捕获,下半部分是来自该周期的捕获 . 我已经提供了下面的详细信息和代码 .

OpenCV 2.4.2在BeagleBone Black上运行,其上安装了Ångström . 连接到BeagleBone Black USB的摄像头是Logitech C920 . 在通过5 V电源供电并将BeagleBone Black连接到笔记本电脑之前,相机连接到BeagleBone Black . 访问是通过PuTTY .

代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cxcore.h>
#include "LaserWeed.h"
#include "SimpleGPIO.h"

using namespace cv;

int main(int argc, char* argv[])
{
    int i=0, a;
    string name;
    int length;
    char c, Filename[10000];
    CvCapture* capture = NULL;
    IplImage* img = NULL;

    do
    {
        //I am not sure if this is necessary, but I tried anyway
        //to see if it makes a difference since upper half of
        //image was from previous cycle.
        capture = NULL;
        img = NULL;

        //Converting Numbers to string to save with proper name
        std::stringstream ss;
        ss << i;
        name = ss.str();
        name = name + ".jpg";
        length = name.size();
        for(a=0; a<length; a++)
        {
            Filename[a] = name[a];
        }

        capture = cvCaptureFromCAM(-1);
        if (!capture)
        {
            fprintf( stderr, "ERROR: capture is NULL \n" );
            getchar();
            return -1;
        }
        img = cvQueryFrame(capture);
        if (!img)
        {
            fprintf(stderr, "ERROR: img is null...\n");
            getchar();
            return -1;
        }

        cvSaveImage(Filename,img);
        cvReleaseCapture(&capture);
        cvReleaseImage(&img);

        i++;
        c = getchar();
    }
    while (c!='e')
        ;
    return 0;
}

我哪里可能出错?

Stack Overflow问题BeagleBone, OpenCV and webcam issue有点类似的问题 . 但重新安装操作系统将是我的最后选择 .

1 回答

  • 0

    这很奇怪,无论如何都试图将捕获从do-while循环中取出,可能每次打开和释放捕获设备都不会给相机准备它的图像缓冲区足够的时间 .

相关问题