【问题标题】:Why would my OpenCV program on BeagleBone Black capture images like this?为什么我在 BeagleBone Black 上的 OpenCV 程序会捕获这样的图像?
【发布时间】:2013-12-05 14:11:43
【问题描述】:

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

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

OpenCV 2.4.2 在BeagleBone Black 上运行,上面安装了Ångström。 插入 BeagleBone Black 的 USB 的摄像头是罗技 C920。 相机先连接到 BeagleBone Black,然后通过 5 V 电源供电并将 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;
}

我可能哪里出错了?

堆栈溢出问题BeagleBone, OpenCV and webcam issue 有点类似的问题。但重新安装操作系统将是我最后的选择。

【问题讨论】:

    标签: opencv webcam beagleboneblack logitech


    【解决方案1】:

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

    【讨论】:

    • 当然。相机初始化必须在循环外执行。取决于驱动程序初始化(如果每次都会重新初始化相机),但基本上相机需要一些时间来启动和运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多