I hope that you can help me...
I have an IplImage (reimg_right) 320 X 240, IPL_DEPTH_32F
and I want to save it as an image and as an xml file.
I use this code:
sprintf(name1,"path1/image.bmp");
sprintf(name2,"path2/feature_image32F.xml");
cvSaveImage(name1,reimg_right);
cvSave(name2, reimg_right, NULL, NULL, cvAttrList(0,0));
all is ok but the problem is that in the xml file I don't have a matrix 320 X 240 but a matrix 19200 X 4 !!!
someone knows how to hold the dimensions?
thanks gabriele
I don't know what OpenCV version you are using, but some time ago you could do just:
cvSave("file.xml", my_img);
assuming my_img as:
CvMat* my_img = cvCreateMat(320, 240, CV_32FC1);
But since you are using an IplImage, you could convert them like:
CvMat mat;
CvMat* my_img = cvGetMat(reimg_right, &mat);
cvSave("file.xml", my_img);
Related
I'm working with OpenCV 2.4.11 in C on Code::Blocks, in particular through the O'Reilly book Learning OpenCV. The section on the watershed algorithm was a bit short, so I thought I'd play with it a bit to see how exactly it works. However, every time I call the function I get the following error:
OpenCV Error: Unsupported format or combination of formats (Only 32-bit, 1-chann
el output images are supported) in cvWatershed
My program so far is very simple:
int main(int arg, int arg2) {
//open windows
cvNamedWindow("Input", 1 );
cvNamedWindow("Markings", 1 );
//load images
IplImage* input = cvLoadImage("ActualDoorPhoto.jpg", CV_LOAD_IMAGE_COLOR);
assert(input != NULL);
IplImage* markingstemp = cvLoadImage("ActualMarkingTest.jpg", CV_LOAD_IMAGE_COLOR);
assert(markingstemp != NULL);
//prepare markings
IplImage* markings = cvCreateImage(cvGetSize(markingstemp), 32, 1);
CvMat* markmat = cvCreateMat(input->width, input->height, CV_32FC1);
cvWatershed(input, markmat);
cvShowImage("Input", input);
cvShowImage("Markings", markings);
cvWaitKey(0);
return 0;
}
I have tried putting both markings and markmat as the second argument for cvWatershed, as well as several other things (notably markings with the contours of markingstemp drawn onto it), but every time I get the same error. Can anyone tell me what I'm doing wrong?
You're inverting the dimensions of the output matrix. It should be:
CvMat* markmat = cvCreateMat(input->height, input->width, CV_32FC1);
The format should also probably be changed to CV_32SC1.
I have a data array of pixel intensity (e.g. unsigned char pixel_intensity[4] = {0, 255, 255, 0}) and I need to create image in C code on Linux (Raspberry Pi).
What is the easiest way to do it?
I would suggest using the netpbm format as it is very easy to program. It is documented here and here.
I have written a little demonstration of how to write a simple greyscale ramp to a 100x256 image below.
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *imageFile;
int x,y,pixel,height=100,width=256;
imageFile=fopen("image.pgm","wb");
if(imageFile==NULL){
perror("ERROR: Cannot open output file");
exit(EXIT_FAILURE);
}
fprintf(imageFile,"P5\n"); // P5 filetype
fprintf(imageFile,"%d %d\n",width,height); // dimensions
fprintf(imageFile,"255\n"); // Max pixel
/* Now write a greyscale ramp */
for(x=0;x<height;x++){
for(y=0;y<width;y++){
pixel=y;
fputc(pixel,imageFile);
}
}
fclose(imageFile);
}
The header of the image looks like this:
P5
256 100
255
<binary data of pixels>
And the image looks like this (I have made it into a JPEG for rendering on here)
Once you have an image, you can use the superb ImageMagick (here) tools to convert the image to anything else you like, e.g. if you want the greyscale created by the above converted into a JPEG, just use ImageMagick like this:
convert image.pgm image.jpg
Or, if you want a PNG
convert image.pgm image.png
You can actually use the PGM format images directly on the web, by convention, the MIME type is image/x-portable-graymap
Hi I am trying to stitch some images without using the stitch class provided by opencv. But, the output is quit unexpected.
I will explain it with the input and output image.
input1
input2
expected output
real output
I think something is wrong with my ROI copying. anybody please help !!!
My code for stitching part is as follows-
std::vector< Point2f > points1,points2;
for( int i = 0; i < matches1.size(); i++ )
{
points1.push_back( keypoints_input1[matches1[i].queryIdx ].pt );
points2.push_back( keypoints_input2[matches1[i].trainIdx ].pt );
}
/* Find the Homography Matrix for current and next frame*/
Mat H1 = findHomography( points2, points1, CV_RANSAC );
/* Use the Homography Matrix to warp the images*/
cv::Mat result1;
warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150), INTER_CUBIC);
Mat stitch_1(Size(input2.cols+150, input2.rows+150),CV_8UC3);
Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows));
Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows));
input2.copyTo(roi1);
result1.copyTo(roi2);
Can anybody tell me where I am going wrong ? thanks.
Edit: input1(640,360) and input2(790,510) are of different size.
I hope that this example helps you.
It's interesting to test on different images.
EDIT:
try this code:
Mat stitch_1(Size(input2.cols*2+ input1.rows,input2.rows*2),CV_8UC3);
Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows));
Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows));
result1.copyTo(roi2);
input1.copyTo(roi1);
imshow("final", stitch_1);
I'm trying to use openCV with LabWindows 2012SP1. I've got a simple project attempting to run a simple "Hello World" program in debug mode.
The code I'm trying to run is
#include <cv.h>
#include <highgui.h>
// Create a window to show the image
cvNamedWindow( "My Cool Window", CV_WINDOW_AUTOSIZE );
IplImage *img = cvCreateImage( cvSize( 300, 100 ), IPL_DEPTH_8U, 3 );
double hScale = 1.0;
double vScale = 1.0;
double shear = 0.0;
int lineWidth = 2;
// Initialize the font
CvFont font;
cvInitFont( &font, CV_FONT_HERSHEY_SCRIPT_COMPLEX, hScale, vScale, shear, lineWidth, 8 );
// Write on the image ...
CvScalar color = CV_RGB( 0, 51, 102 );
cvPutText( img, "Hello World!", cvPoint( 60, 60 ), &font, color );
// ... and show it to the world !
cvShowImage( "My Cool Window", img );
// Wait until the user wants to exit
cvWaitKey(0);
and I have the following libraries added:
opencv_core247d.lib (32-bit)
opencv_highgui247d.lib (32-bit)
opencv_imgproc247d.lib (32-bit)
opencv_imgproc247d.dll
However, when I go to run the program in debug mode, I get an error telling me:
The program can't start because opencv_imgproc247d.dll is missing
from your computer. Try reinstalling the program to fix this problem.
I'm more than a little bit confused at this point, as I have the DLL in question added to the project.
Help?
you need to add the location of the opencv dll's to the 'PATH' env var.
please don't use the old c-api (won't be supported in near future), ( IplImages, cv* functions ). use cv::Mat and the c++ api(namespace cv) instead.
I am using OpenCV 2.1 with vs2010(coding in C). After extracting the blue plane from a rgb image, I applied dct to it to get the transformed matrix.
cvDCT(source,destination,CV_DXT_FORWARD);
It is successfully building, but somehow it is not executing
The error is like "Unhandled exception at 0x75c89617 in freqDomain.exe: Microsoft C++ exception: cv::Exception at memory location 0x001ce35c.."
I think the error is in setting the type of cvarray of output image. is it okay to set it to IPL_DEPTH_8U or should it be float?
This is my code snippet:
int main()
{
IplImage *input,*output,*b,*g,*r;
input=cvLoadImage("dolphin.jpg");
int width,height;
width=input->width;
height=input->height;
b=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
g=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
r=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
cvSplit(input,b,g,r,NULL);
cvNamedWindow("blue",CV_WINDOW_AUTOSIZE);
IplImage *b_dct,*g_dct,*r_dct;
b_dct=cvCreateImage(cvSize(width,height),8,1);
g_dct=cvCreateImage(cvSize(width,height),8,1);
r_dct=cvCreateImage(cvSize(width,height),8,1);
cvDCT(b,b_dct,0); // doubt??
cvShowImage("blue",b_dct);
...
yeah found the solution :)
the problem was with the datatype of source image. it should be float or double..
I used cvConvert function to convert from unsigned int to 32 bit float values.