Click here to Skip to main content
12,454,965 members (62,502 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21.2K views
9 bookmarked
Posted

How to Display Image In Picturebox in VC++ from Iplimage and Mat

, 9 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to convert iplimage and Mat to Picture Box in VC++

Introduction

This tip/trick will be useful to OpenCV programmers, who wish to use Windows Form application under Visual C++. This tip helps programmers to use Windows function with OpenCV library. The following tip shows how to assign iplimage and mat variable to picturebox image.

Assign Iplimage to Picturebox Image

In this part, it shows how to assign iplimage to picturebox image. First of all, declare the frame pointer. Iplimage type.

Declare Iplimage variable:

IplImage* frame; 

Here, create new Bitmap image from frame properties like width, height, widthstep. Set image data from frame imagedata.

Process the PictureBox.

pictureBox1->Image  = gcnew System::Drawing::Bitmap
(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
pictureBox1->Refresh(); 

Assign Mat to Picturebox Image

In this part, it shows how to assign Mat to picturebox image. First of all, declare the frameDetected variable, Mat type.

Declare Mat variable.

Mat frameDetected; 

Here, create graphics of picturebox. Then, create new Bitmap image from frameDetected properties like cols, rows, step. Then create Rectangle with x and y with 0 value and width and height with picturebox height, width respectively. Then rectangle assign to previous initialized graphics object.

Process the PictureBox:

System::Drawing::Graphics^ graphics2 = pictureBox3->CreateGraphics();
System::IntPtr ptr2(frameDetected.ptr());
System::Drawing::Bitmap^ b2  = gcnew System::Drawing::Bitmap(frameDetected.cols,
frameDetected.rows,frameDetected.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr2);
System::Drawing::RectangleF rect2(0,0, pictureBox3->Width,pictureBox3->Height);
graphics2->DrawImage(b2,rect2);  

Points of Interest

  • Learn how to assign iplimage to picturebox image
  • Learn how to assign Mat to picturebox image

References

  1. http://opencv.org/
  2. http://en.wikipedia.org/wiki/OpenCV
  3. http://docs.opencv.org/

Sorry

Sorry for my English. If you notice errors or can suggest a more correct version, please let me know.

History

  • 9 March 2014 - First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SOHAM_GANDHI
Software Developer Opulent Infotech
India India
I am Soham Gandhi from India. I studied BE in Information Technology at University of Pune. (www.unipune.ac.in). I have been learning OpenCV, Enjoying it.
My research interest in Image Processing, Artificial Intelligence, Security Systems, Security Metrics. I work on OpenCV, EmguCV, Visual Studio 2008/10, Java platform.

Home Page (Blog)


You Tube Channel

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionWhy IplImage ? Pin
azty6-May-15 7:09
memberazty6-May-15 7:09 
Questionproblem Pin
Member 116666625-May-15 7:50
memberMember 116666625-May-15 7:50 
AnswerRe: problem Pin
SOHAM_GANDHI5-May-15 18:24
professionalSOHAM_GANDHI5-May-15 18:24 
AnswerRe: problem Pin
SOHAM_GANDHI5-May-15 18:26
professionalSOHAM_GANDHI5-May-15 18:26 
GeneralRe: problem Pin
Member 116666627-May-15 7:57
memberMember 116666627-May-15 7:57 
Generalgreat Pin
CHARLIE9126-May-14 19:37
memberCHARLIE9126-May-14 19:37 
Questionit doesn't work for me Pin
Soheil Hasankhani1-Apr-14 3:08
memberSoheil Hasankhani1-Apr-14 3:08 
AnswerRe: it doesn't work for me Pin
SOHAM GANDHI1-Apr-14 4:43
memberSOHAM GANDHI1-Apr-14 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 9 Mar 2014
Article Copyright 2014 by SOHAM_GANDHI
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid