Difference between revisions of "Hello World in C++"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to navigation Jump to search
m (Reverted edits by Inuxejiq (talk) to last revision by Emgucv)
 
Line 1: Line 1:
----
+
<font color=green>''' This project is part of the Emgu.CV.Example solution'''</font>
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://isiqilujev.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 
----
 
=[http://isiqilujev.co.cc CLICK HERE]=
 
----
 
</div>
 
&lt;font color=green>''' This project is part of the Emgu.CV.Example solution'''&lt;/font>
 
  
 
== System Requirement ==
 
== System Requirement ==
Line 20: Line 12:
  
 
== Source Code ==
 
== Source Code ==
&lt;source lang=cpp>
+
<source lang=cpp>
array&lt;Image&lt;Bgr^, Byte>^>^ ImageProcessor::ProcessImage()
+
array<Image<Bgr^, Byte>^>^ ImageProcessor::ProcessImage()
 
{
 
{
 
     //---- plain old Open CV code ----
 
     //---- plain old Open CV code ----
Line 27: Line 19:
 
cvSet(img1, cvScalar(255, 255, 255));
 
cvSet(img1, cvScalar(255, 255, 255));
 
CvFont font;
 
CvFont font;
cvInitFont(&amp;font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
+
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
cvPutText(img1, "Hello, World", cvPoint(50, 100), &amp;font, cvScalar(0.0, 0.0, 0.0));
+
cvPutText(img1, "Hello, World", cvPoint(50, 100), &font, cvScalar(0.0, 0.0, 0.0));
 
//---- end of plain old OpenCV code
 
//---- end of plain old OpenCV code
  
 
//create the managed Emgu::CV::Image array
 
//create the managed Emgu::CV::Image array
array&lt;Image&lt;Bgr^, Byte>^>^ imageArray = gcnew array&lt;Image&lt;Bgr^, Byte>^>(2);
+
array<Image<Bgr^, Byte>^>^ imageArray = gcnew array<Image<Bgr^, Byte>^>(2);
 
 
 
//---- Copying image from IplImage to Emgu::CV::Image class
 
//---- 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
 
//create a managed Image of the same size, this image will be displayed on the LHS of the GUI
imageArray[0] = gcnew Image&lt;Bgr^, Byte>(img1->width, img1->height);
+
imageArray[0] = gcnew Image<Bgr^, Byte>(img1->width, img1->height);
 
//copy the image from unmanaged IplImage to the managed image
 
//copy the image from unmanaged IplImage to the managed image
 
cvCopy(img1, imageArray[0]->Ptr.ToPointer());
 
cvCopy(img1, imageArray[0]->Ptr.ToPointer());
Line 42: Line 34:
  
 
//---- Release the Unmanaged IplImage ----
 
//---- Release the Unmanaged IplImage ----
cvReleaseImage(&amp;img1);
+
cvReleaseImage(&img1);
 
 
 
//---- Image Processing in EmguCV using .Net Syntax
 
//---- Image Processing in EmguCV using .Net Syntax
 
//another image to be displayed on the RHS of the GUI
 
//another image to be displayed on the RHS of the GUI
imageArray[1] = gcnew Image&lt;Bgr^, Byte>(imageArray[0]->Width, imageArray[0]->Height);
+
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;
 
//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]->SetRandNormal(MCvScalar(50.0, 50.0, 50.0), MCvScalar(10.0, 10.0, 10.0));
Line 54: Line 46:
 
return imageArray;
 
return imageArray;
 
}
 
}
&lt;/source>
+
</source>
  
 
== Result ==
 
== 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