Difference between revisions of "Hello World in C++"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | + | <font color=green>''' This project is part of the Emgu.CV.Example solution'''</font> | |
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== System Requirement == | == System Requirement == | ||
Line 20: | Line 12: | ||
== Source Code == | == Source Code == | ||
− | + | <source lang=cpp> | |
− | array | + | 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(& | + | cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0); |
− | cvPutText(img1, "Hello, World", cvPoint(50, 100), & | + | 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 | + | 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 | + | 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(& | + | 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 | + | 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; | ||
} | } | ||
− | + | </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;
}