I am using OpenCV 2.4.8 on VS2013. I have the following snippet of code:
Mat img_sum = Mat::zeros(img_gray.size(), CV_32F);
char file_name[FILENAME_MAX];
for (int i = 0; i < SCALE_SIZE; i++){
for (int j = 0; j < ORIENTATION_SIZE; j++){
Mat srcImg;
g_gabor[i*ORIENTATION_SIZE + j].conv_img(img_gray, srcImg, CV_GABOR_REAL);
memset(file_name, NULL, FILENAME_MAX);
sprintf_s(file_name, "gabor_images/%d_%d.png", i, j);
imwrite(file_name, srcImg);
imshow("Gabor滤波结果", srcImg); //此时srcImg.type() == 1
waitKey(100);
}
}
imwrite("img_sum.png", img_sum);
The key issue is result of imwrite and imshow. They gave me different result.
The imshow image: imshow image
And, the imwrite image: imwrite image
I was wonderring if the reason is the image type. If so, how to convert image type to solve the problem.
With type CV_32F
, you have to multiply your image by 255 before using imwrite.
Try imwrite(file_name, 255 *srcImg);
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With