开发者

OpenCV : How to display a picture when clicking button in a form

I have made a C++ win32 console application in VS 2008. I open an image in a window. I want to achieve the same result by clicking a button on a form and the image appearing in a picturebox for instance pictureBox1.

So, I made a C++ windows form project and pasted this code in the public area, and it gave me a heap of errors. Do I need a toolkit or something to make the GUI stuff work ?

I really dont know how to make it work for something this small, and I would like to know how.


CODE


#include "stdafx.h"
#include "highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
    const char* imagename = "lena.jpg";

    cv::Mat img = cv::imread(imagename); // Matlab style cvLoadImage another function call
    if(img.empty())
    {
        fprintf(stderr, "Food not load image% S\n", imagename);
        return -1;
    }

    if( !img.data ) // Check for correct loading images
        return -1;

    cv::namedWindow("image", CV_WINDOW_AUTOSIZE); // create a window
    cv::imshow("image", img); // display images

    cv::waitKey();

 开发者_开发技巧   return 0;
}

Many Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜