Reputation: 2669
I am trying to resize an IplImage image in javacv. I found the cvResize function that does such a thing. MY workflow is: to open the image to transform it to gray_scale to resize it to desirable size and finally to reshape it. I have already read it transform it to gray_scale and resize it. What is my problem the final step, reshaping. I have the cvReshape which does what I want. I ve got an IplImage, I have to transform it to cvMat. The next step is reshaping, which takes 4 arguments, a cvArr a cvMat and the desirable dimensions.
// read an image
final IplImage image = cvLoadImage("ef.jpg");
//create image window named "My Image"
final CanvasFrame canvas = new CanvasFrame("My Image");
// request closing of the application when the image window is closed
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
// show image on window
canvas.showImage(image);
IplImage GrayImage = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
cvCvtColor(image, GrayImage, CV_BGR2GRAY);
IplImage img = IplImage.create(60, 60, IPL_DEPTH_8U, 1);
//resize the image
cvResize(GrayImage, img, CV_INTER_LINEAR);
cvSaveImage("4-rjb" + ".jpg", img);
//cvReleaseImage(result1);
System.out.println("The size of the image: "+img);
CvMat mtx = CvMat.createHeader(img.height(), img.width());
cvGetMat(img, mtx, null, 0);
System.out.println(mtx);
cvReshape(img, mtx, 3600, 1);
I am receiving the error:
OpenCV Error: Bad number of channels () in unknown function, file .\src\array.cpp,
line 2721
I ve just want to reshape a 2d image, why that bad number of channels error happened??
Upvotes: 0
Views: 1311
Reputation: 8113
With some Googling I found that your output matrix must contain at least 3 channels. (Blue, Green and Red). Where Blue and Green will be completely empty and you put your grayscale image as Red channel of the output image. Any other number of channels will cause the error you are getting.
Upvotes: 2