Hi all, I am trying to do some gui to show original image, gray, blur, and other things with visual studio c++ WinForms. I wanted to show the mat images in picturebox and I found some examples to do it. I can show images in picturebox now. However when I try to shown gray scale image in picture box, I get different color additional to gray image. I see different colors. I also open gray image with imshow, There is no problem with image. I think conversion keeps other 2 channels. I have searched very long time but I could not find any answers for my problem.
I tried to add a link which shows result of my gui. However my karma is not enough to share link
all Suggestions are appreciated.
System::Drawing::Image^ OpencvReadPicture() {
cv::Mat originalImage ;
originalImage = cv::imread("banana.jpg", cv::ImreadModes::IMREAD_COLOR);
cv::imshow("OriginalImage",originalImage);
System::Drawing::Bitmap^ bitmap = gcnew System::Drawing::Bitmap(originalImage.cols, originalImage.rows, originalImage.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, System::IntPtr::IntPtr(originalImage.data));
System::Drawing::Image^ image = static_cast<System::Drawing::Bitmap^>(bitmap);
return image ;
};
System::Drawing::Image^ OpencvGrayPicture() {
cv::Mat grayImage;
cv::cvtColor(originalImage, grayImage, CV_BGR2GRAY,1);
cv::imshow("GrayImage", grayImage);
System::Drawing::Bitmap^ bitmapGray = gcnew System::Drawing::Bitmap(grayImage.cols, grayImage.rows, grayImage.step, System::Drawing::Imaging::PixelFormat::Format8bppIndexed, System::IntPtr::IntPtr(grayImage.data));
System::Drawing::Image^ imageGray = static_cast<System::Drawing::Bitmap^>(bitmapGray);
return imageGray;
};
pBoxOriginalImage->Image =OpencvReadPicture();// showing original image in the picture box.
pBoxGrayImage->Image = OpencvGrayPicture();// showing gray image in the picturebox.