1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
using namespace std;
int main()
{
//load images
for(int i=1; i<=25; i++)
{
char filename[50];
sprintf( filename, "brain_mri_%d.jpg", i );
IplImage *img=cvLoadImage( filename, CV_LOAD_IMAGE_GRAYSCALE);
if (!img)
{
printf("Error: Image not found.\n");
return 2; //error : not found image
}
cvNamedWindow("Projet Image", CV_WINDOW_AUTOSIZE);// create a window
IplImage *img2=cvCloneImage(img); //cloner img
cvShowImage("Projet Image", img2); //display the image in a window
cvWaitKey(0); //attendre touche
cvDestroyWindow("Projet Image"); //destroy the window
cvReleaseImage(&img); //memory
return 0; //finish with success
//convert IplImage -> Matrix
int height = img->height;
int width = img->width;
CvMat *mat = cvCreateMat(height,width,CV_32FC3 );
//convert Matrix -> Vector
//CvMat row_header, *row;
//row = cvReshape(mat, &row_header, 0, 1);
CvMat vector_header;
cvReshape(img, &vector_header, 0, 1);
//check the height and width of vector_header
if(vector_header.height != 1)
{
fprintf(stderr, "vector_header's height is %d\n", vector_header.height);
}
if(vector_header.width != width*height)
{
fprintf(stderr, "vector_header's width is %d\n", vector_header.width);
}
}
}
|