ejohns85
March 25th, 2009, 02:58 PM
Hello,
I want to use OpenCV to load a file, perform edge detection on it, and then save the image containing these edges. Below is my source code:
// Load an image from a specified path
IplImage* image1 = cvLoadImage("C:\\image.bmp");
// Create a grayscale image of image1
IplImage* image1Gray = cvCreateImage(cvGetSize(image1), image1->depth, 1);
// Convert image1 into a grayscale image, image1Gray
cvCvtColor(image1, image1Gray, CV_BGR2GRAY);
// Create another image in the same format as the original image, to store the edge data
edges1 = cvCreateImage(cvGetSize(image1), image1->depth, 1);
// Create an image to store the edge data, now with 3 channels
IplImage* edges1BGR = cvCreateImage(cvGetSize(image1), image1->depth, 3);
// Actually convert edges1BGR to a 3-channel image
cvCvtColor(edges1, edges1BGR, CV_GRAY2BGR);
// Save the image
cvSaveImage("C:\\edges.bmp", image1);
The problems is, the saved image is just an image of vertical black and white stripes. I know that the edge detection has worked correctly, because if I use cvShowImage() to display the edges, all the edges look fine. It must be something to do with the format in which I am saving the image.
Please help :)
I want to use OpenCV to load a file, perform edge detection on it, and then save the image containing these edges. Below is my source code:
// Load an image from a specified path
IplImage* image1 = cvLoadImage("C:\\image.bmp");
// Create a grayscale image of image1
IplImage* image1Gray = cvCreateImage(cvGetSize(image1), image1->depth, 1);
// Convert image1 into a grayscale image, image1Gray
cvCvtColor(image1, image1Gray, CV_BGR2GRAY);
// Create another image in the same format as the original image, to store the edge data
edges1 = cvCreateImage(cvGetSize(image1), image1->depth, 1);
// Create an image to store the edge data, now with 3 channels
IplImage* edges1BGR = cvCreateImage(cvGetSize(image1), image1->depth, 3);
// Actually convert edges1BGR to a 3-channel image
cvCvtColor(edges1, edges1BGR, CV_GRAY2BGR);
// Save the image
cvSaveImage("C:\\edges.bmp", image1);
The problems is, the saved image is just an image of vertical black and white stripes. I know that the edge detection has worked correctly, because if I use cvShowImage() to display the edges, all the edges look fine. It must be something to do with the format in which I am saving the image.
Please help :)