Hello World in C++: Difference between revisions

From EMGU
Jump to navigation Jump to search
New page: <source lang=cpp> array<Image<Bgr^, Byte>^>^ ImageProcessor::ProcessImage() { //---- plain old Open CV code ---- IplImage* img1 = cvCreateImage(cvSize(300, 200), IPL_DEPTH_8U, 3); cv...
 
m Reverted edits by Inuxejiq (talk) to last revision by Emgucv
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<font color=green>''' This project is part of the Emgu.CV.Example solution'''</font>
== System Requirement ==
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
!Component || Requirement || Detail
|-
|Emgu CV || [[Version_History#Emgu.CV-2.0.0.0_Alpha|Version 2.0.0.0 Alpha]] ||
|-
|Operation System || Windows Only || Mono cannot compile managed C++
|}
== Source Code ==
<source lang=cpp>
<source lang=cpp>
array<Image<Bgr^, Byte>^>^ ImageProcessor::ProcessImage()
array<Image<Bgr^, Byte>^>^ ImageProcessor::ProcessImage()
Line 35: Line 48:
</source>
</source>


== Result ==
[[image:cplusplusExample.png|300px|center|thumb|Result of C++ Example]]
[[image:cplusplusExample.png|300px|center|thumb|Result of C++ Example]]

Latest revision as of 13:43, 30 November 2010

This project is part of the Emgu.CV.Example solution

System Requirement

Component Requirement Detail
Emgu CV Version 2.0.0.0 Alpha
Operation System Windows Only Mono cannot compile managed C++


Source Code

array<Image<Bgr^, Byte>^>^ ImageProcessor::ProcessImage()
{
    //---- plain old Open CV code ----
	IplImage* img1 = cvCreateImage(cvSize(300, 200), IPL_DEPTH_8U, 3);
	cvSet(img1, cvScalar(255, 255, 255));
	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
	cvPutText(img1, "Hello, World", cvPoint(50, 100), &font, cvScalar(0.0, 0.0, 0.0));
	//---- end of plain old OpenCV code

	//create the managed Emgu::CV::Image array
	array<Image<Bgr^, Byte>^>^ imageArray = gcnew array<Image<Bgr^, Byte>^>(2);
	
	//---- Copying image from IplImage to Emgu::CV::Image class
	//create a managed Image of the same size, this image will be displayed on the LHS of the GUI
	imageArray[0] = gcnew Image<Bgr^, Byte>(img1->width, img1->height);
	//copy the image from unmanaged IplImage to the managed image
	cvCopy(img1, imageArray[0]->Ptr.ToPointer());
	//---- End of image copying

	//---- Release the Unmanaged IplImage ----
	cvReleaseImage(&img1);
	
	//---- Image Processing in EmguCV using .Net Syntax
	//another image to be displayed on the RHS of the GUI
	imageArray[1] = gcnew Image<Bgr^, Byte>(imageArray[0]->Width, imageArray[0]->Height);
	//fill the image with random colors of mean 50 and standard deviation of 10;
	imageArray[1]->SetRandNormal(MCvScalar(50.0, 50.0, 50.0), MCvScalar(10.0, 10.0, 10.0));
	imageArray[1] = imageArray[0] - imageArray[1]; //add the noise to the image
	//---- End of Image Processing in Emgu CV.

	return imageArray;
}

Result

Result of C++ Example