0

Hello,

Im new to programming with openCV. I gotta do some geometrical transformations on an image, like translation,rotation, scaling, etc... I still dnt know how transformations are done in opencv. I looked in a cv refenrence manual and found a couple of functions many on resizing and rotation. I tried to do resizing on an image but it didnt work. Instead of describing what i did, i attached the file.cpp witch has my code. I think, this is better. The project compiled successfully but when I ran it, it gave null pointer (null array pointer) exception in Function cvGetMat... Please have a look at my code. Tell me your feedback and also tell me if you know were to find more about doing transformations on images on opencv or if you can tell me right away it wil be great. Any help, will be greatly appreciated. Thanks for your support!

Attachments
// 2d Image Transformations.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <algorithm>
using namespace std;

static IplImage* img;
static CvArr* resized;

static int height,width,step,channels;
static uchar *data;
static int i,j,k;


void arithScalling(IplImage* img, int x)
{

	IplImage* bw=cvCloneImage(img);

	static int height,width,step,channels;
	static uchar *data;
	static int i,j,k;

	height    = bw->height;
	width     = bw->width;
	step      = bw->widthStep;
	channels  = bw->nChannels;

	data      = (uchar *)bw->imageData;

	printf("%i",step);
		
	cvResize(bw, resized, x);

	cvNamedWindow( "Image Scalling", CV_WINDOW_AUTOSIZE);
	cvShowImage( "Image Scalling", resized);
	cvSaveImage("Scaled Image.jpg",resized);
}




int _tmain(int argc, _TCHAR* argv[])
{
	img=cvLoadImage("gt2.jpg",-1);
	if(!img) printf("Could not load image file: %s\n");

	CvArr *bw = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1);
	bw = cvCloneImage(img);



	arithScalling(img,5);
	cvWaitKey(0);
	return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by hemant_chawla89
0

hi
were you able to resolve the null pointer to cvmat error , please tell me how to resolve it . i get the same error while trying to open an image from current directory .

heres my code:

int main( int argc, char** argv ) 
{
    char buffer[_max_path];
if( _getcwd( buffer, _MAX_PATH ) == NULL )
      perror( "_getcwd error" );
   else
      printf( "%sn", buffer );

    int height = 620;int width = 440;
CvPoint pt = cvPoint( height/4, width/2 );

//IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3);
IplImage* hw = cvLoadImage( "image0002A.jpg" );

cvSet(hw,cvScalar(0,0,0));
CvFont font;
cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,1.0, 1.0, 0, 1, CV_AA);
//cvPutText(hw, "To OpenCV", pt, &font, CV_RGB(150, 0, 150) );
cvNamedWindow("Hello World", 0);//display the image in the container
cvShowImage("Hello World", hw);//hold the output
cvWaitKey(0);
return 0;
}

Hello,

Im new to programming with openCV. I gotta do some geometrical transformations on an image, like translation,rotation, scaling, etc... I still dnt know how transformations are done in opencv. I looked in a cv refenrence manual and found a couple of functions many on resizing and rotation. I tried to do resizing on an image but it didnt work. Instead of describing what i did, i attached the file.cpp witch has my code. I think, this is better. The project compiled successfully but when I ran it, it gave null pointer (null array pointer) exception in Function cvGetMat... Please have a look at my code. Tell me your feedback and also tell me if you know were to find more about doing transformations on images on opencv or if you can tell me right away it wil be great. Any help, will be greatly appreciated. Thanks for your support!

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.