更新Cimg图像并通过回调功能显示

时间:2019-04-03 04:28:17

标签: c++ cimg

我正在编写一些C ++代码来显示从相机获得的图像。在代码中,每当有新图像通过时,相机都会调用一个回调函数,我将在存储该图像的内存中获得一个指针。现在,我想使用CImg每次通过图像时都显示图像(如视频),并可能使用CImg中的函数来处理图像。

我正在考虑从回调函数中的指针定义Cimg实例,并将CImg display的指针发送给回调函数。因此,每次调用回调函数时,实例都会被覆盖,然后显示新图像。

struct data {
    CImgDisplay* disp;
};


int callBack(int Nimg, data *pointersPassedIn){
    auto   disp = pointersPassedIn->disp;
    int   width,height;
    getParameter(WIDTH, &width);//Retrieve height and width of the image from camera
    getParameter(HEIGHT, &height);
    unsigned short* imgPtr = (unsigned short*)getImagePtr(Nimg);//Retrieve image pointer from camera, as 16-bit image, use unsigned short
    CImg <unsigned short> img(imgPtr ,width,height);
    disp->render(img);
    disp->paint();
    return 0 ;
};

int main(){
    int width,height;
    getParameter(WIDTH, &width);
    getParameter(HEIGHT, &height);
    CImgDisplay disp(width,height);
    registerCallBack(&disp);//will add &disp to struct data and send it to call back function
    aquire();
    while (!disp.is_closed()){
        ;
    }
    stopAquire();
};

但是,仅显示一张图像,然后程序退出自身。

谢谢

0 个答案:

没有答案
相关问题