OpenCV basics-Image Display and opencv Basics

Source: Internet
Author: User

OpenCV basics-Image Display and opencv Basics

After completing the opencv configuration above, you often need to display images. The videos and tests to be discussed later are also based on the pictures, we will share the following:


I. OpenCV + win32


After creating a win32 null document, add the cpp file of the new project and directly run the Code:


# Include "highgui. h "// This header file is often used. In opencv, int main () {IplImage * img = cvLoadImage (" E: \ lena.jpg "); // load the image, use an iplimage pointer to point to the file address cvNamedWindow ("Example", CV_WINDOW_AUTOSIZE); // name an example window. The window attribute is CV_WINDOW_AUTOSIZE, and there are other attributes, you can learn about cvShowImage ("Example", img); // imgcvWaitKey (0) is displayed in the window named example; // wait. If you do not add this sentence, basically, it is a transient cvReleaseImage (& img); // release the resource cvDestroyWindow ("Example"); // destroy the window and return 0 ;}


Ii. OpenCV + MFC


Create an MFC project. In the displayed dialog box, drag the picture control into the dialog box. Assume that the ID number is IDC_STATIC2, and a button. Assume that the name is button1.


// The showimage function is used to display the image void CtestDlg: ShowImage (IplImage * img, UINT id) in the specified ID control) // ID is the ID of the Picture Control. {CDC * pDC = GetDlgItem (ID)-> GetDC (); // obtain the dc hdc hDC = pDC-> GetSafeHdc () of the display control; // obtain the HDC (device handle) for the drawing operation CRect rect; GetDlgItem (ID) -> GetClientRect (& rect); CvvImage cimg; cimg. copyOf (img); // copy the image cimg. drawToHDC (hDC, & rect); ReleaseDC (pDC);} void CtestDlg: OnBnClickedbutton1 () // The response function of the buttons {IplImage * img = cvLoadImage ("E: \ lena.jpg "); ShowImage (img, IDC_STATIC2); // call the showiamge function to display the image cvReleaseImage (& img) in the picture control; // release}


Note: My project named test is created, so the class is also test. After mfc is created, a lot of code will appear, and you can directly run it to see the interface, I will mainly give the key functions and implementations here, without the declaration in the class .. Reference and writing will be successful.



The display of the image is basically over. If there is anything wrong, please also point out that learning from each other





Opencv cannot read the image

The image reading path is incorrect. The absolute path should be written.

Opencv cannot read the image

Are your images in the relative path? If yes, delete the second parameter of cvLoadImage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.