How to Create RGB Bitmap Using Visual C++?
I've been given an assignment to create a RGB bitmap image, provided that the configuration values are given.
And I,ve been told to use visual c++ along with opencv to create the image.
As I'm new in both visual c++ and OpenCV, how to use those tool开发者_Python百科s to create Bitmap? Is there any tutorial that I can use?
This is a really broad question, because I have no idea where your image data is coming from. Are you reading in other image data and saving it to a bitmap? Are you transforming it somehow? If not, are you just programatically filling in the pixels (i.e. create a bitmap filled with a specific color). I'll assume for a minute that the latter is the case.
// Create an empty 3 channel (RGB) image
IplImage* img = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 3);
// Iterate over all of the rows of the image
for(int y = 0; y < 480; ++y)
{
// Iterate over all of the columns of each row
for(int x = 0; x < 640; ++x)
{
// Set each pixel to solid red
((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 0] = 0; // B
((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 1] = 0; // G
((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 2] = 255; // R
}
}
// Save the image data as a bitmap
cvSaveImage("ImAfraidICantLetYouDoThatDave.bmp", img);
// Clean up our memory
cvReleaseImage(&img);
I based all of this on code available at:
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html
Since you're new to visual studio, a fair warning: getting opencv set up under windows is less than trivial. There are plenty of tutorials out there though, so I'm sure you can figure it out. I hope this is helpful.
精彩评论