Hello,

I am having a few problems with my image class using OpenCV.
I am getting the errors:

src/image.cpp: In constructor ‘Image<T>::Image(const char*, bool)’:
src/image.cpp:21: error: there are no arguments to ‘cvLoadImage’ that depend on a template parameter, so a declaration of ‘cvLoadImage’ must be available
src/image.cpp:21: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
src/image.cpp:23: error: there are no arguments to ‘cvLoadImage’ that depend on a template parameter, so a declaration of ‘cvLoadImage’ must be available
src/image.cpp: In member function ‘void Image<T>::save(const char*)’:
src/image.cpp:44: error: there are no arguments to ‘cvSaveImage’ that depend on a template parameter, so a declaration of ‘cvSaveImage’ must be available

The header file is pretty standard, including cv.h for the required functions.

Code snippets below, with full files attached (image.hpp renamed to image.h otherwise it would not allow upload):

image.cpp Lines 18-25:

template<class T>
   Image<T>::Image(const char* filename, bool color = true) {

       if(color) {

         imgp = cvLoadImage(filename);         

       } else {

         imgp = cvLoadImage(filename,0);     

       } 

   }

image.cpp Lines 42-45:

template<class T>
   
void Image<T>::save(const char* filename) {

       cvSaveImage(filename, imgp); 

   }

Thanks alot for any help :)
Adam

Attachments
#ifndef IMAGE_C
#define IMAGE_C

#include "image.hpp"

using namespace std;

   template<class T>
   Image<T>::Image() {
          imgp = 0;          
   }

   template<class T>
   Image<T>::Image(IplImage* img) {
          imgp = cvCloneImage(img);          
   }
   
   template<class T>
   Image<T>::Image(const char* filename, bool color = true) {
       if(color) {
         imgp = cvLoadImage(filename);         
       } else {
         imgp = cvLoadImage(filename,0);     
       } 
   }
   
   template<class T>
   Image<T>::Image(int width, int height, bool color = true) {
       CvSize size = cvSize(width,height);
       if(color) {
         imgp = cvCreateImage(size,IPL_DEPTH_8U,3);    
       } else {
					imgp = cvCreateImage(size,IPL_DEPTH_8U,1);
       }             
   } 

   template<class T>
   Image<T>::~Image() {
       imgp = 0;         
   }
   
   template<class T>
   void Image<T>::save(const char* filename) {
       cvSaveImage(filename, imgp); 
   }
   
   template<class T>
   void Image<T>::makeGray() {
   	//IMPLEMENT
   	return;
   }
   
   template<class T>
   void Image<T>::operator=(IplImage* img) {
       imgp = img;    
   }
   
   template<class T>
   int Image<T>::getWidth() {
       return imgp->width;     
   }
   
   template<class T>
   int Image<T>::getHeight() {
       return imgp->height;     
   }
   
   template<class T>
   bool Image<T>::isColor() {
       return imgp->nChannels == 3; 
   } 
   
   template<class T>
   IplImage* Image<T>::returnImg() {
       return imgp;      
   }   
   
   template<class T>
   inline T* Image<T>::operator[](const int rowIndx) {
       return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));
   }
   
   template<class T>
   void Image<T>::setRGB(int x, int y, int r, int g, int b) {
       (*this)[x][y].r = r;
       (*this)[x][y].g = g;
       (*this)[x][y].b = b;
   }
   
   template<class T>
   void Image<T>::setRGB(int x, int y, float r, float g, float b) {
       (*this)[x][y].r = r;
       (*this)[x][y].g = g;
       (*this)[x][y].b = b;
   }

#endif
#ifndef IMAGE_H
#define IMAGE_H

#include "cv.h"
#include "ex.cpp"

using namespace std;
template<class T>
class Image {
   IplImage* imgp;
   
   public:
   //Default constructor
   Image();
   
   //Copy constructor
   Image(IplImage* img);
   
   //Load image from file constructor, color defaults to true
   Image(const char* filename, bool color);
   
   //New image constructor, wityh width and height values.
   Image(int width, int height, bool color);
   
   //Destructor
   ~Image();
   
   void save(const char* filename);
   
   void makeGray();
   
   void operator =(IplImage* img);
   
   int getWidth();
   
   int getHeight();
   
   bool isColor();
    
   IplImage* returnImg();
   
   T* operator[](const int rowIndx);
   
   void setRGB(int x, int y, int r, int g, int b);
   
   void setRGB(int x, int y, float r, float g, float b);
   
};

typedef struct{
  unsigned char b,g,r;
} RgbPixel;

typedef struct{
  float b,g,r;
} RgbPixelFloat;

typedef Image<RgbPixel>       RgbImage;
typedef Image<RgbPixelFloat>  RgbImageFloat;
typedef Image<unsigned char>  BwImage;
typedef Image<float>          BwImageFloat;


#endif

Hello,

I have read through that link. I am still at a loss as to exactly what i have done wrong, and how i would go about fixing it.

Any advice is much appreciated
Adam

That link deals entirely with your exact problem and why it occurs, and tells you how to fix or avoid it. Please read it through carefully, again. this->imgp = cvLoadImage( filename ); cvSaveImage( filename, this->imgp ); Good luck.

Hello,

The compiler has no errors now, thank you :)

The linker on the other hand.... I am getting:

g++ main.o image.o -o tpp1 `pkg-config --cflags opencv` `pkg-config --libs opencv`
main.o: In function `main':
main.cpp:(.text+0x8a): undefined reference to `Image<RgbPixel>::Image()'
main.cpp:(.text+0x93): undefined reference to `Image<RgbPixel>::Image()'
main.cpp:(.text+0x13b): undefined reference to `Image<RgbPixel>::Image(char const*, bool)'
main.cpp:(.text+0x14c): undefined reference to `Image<RgbPixel>::~Image()'
main.cpp:(.text+0x1e7): undefined reference to `Image<RgbPixel>::~Image()'
main.cpp:(.text+0x200): undefined reference to `Image<RgbPixel>::~Image()'
main.cpp:(.text+0x212): undefined reference to `Image<RgbPixel>::~Image()'
main.cpp:(.text+0x237): undefined reference to `Image<RgbPixel>::~Image()'
collect2: ld returned 1 exit status

My files are attached. Code is mostly the same as first post bar a few fixes to make it compile.

Thanks
Adam

Attachments
This article has been dead for over six months. Start a new discussion instead.