开发者

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

开发者 https://www.devze.com 2023-01-08 15:20 出处:网络
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 instan

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

精彩评论

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