I'm getting an undefined reference to cv::Mat::Mat error when i compile this program
Â
#include <opencv/cv.h>
#include <highgui.h>
#include <stdio.h>
#include <limits>
#include <stdlib.h>
Â
using namespace cv;
using namespace std;
Â
IplImage* g_image = NULL;
IplImage* g_gray = NULL;
int g_thresh = 100;
CvMemStorage* g_storage = NULL;
Â
void on_trackbar(int)
{
if( g_storage == NULL )
{
g_gray = cvCreateImage( cvGetSize( g_image ), 8, 1 );
g_storage = cvCreateMemStorage(0);
}
else
{
cvClearMemStorage( g_storage );
}
Â
CvSeq* contours = 0;
cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );
if( contours )
{
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100 );
}
cvShowImage( "Contours", g_gray );
}
Â
Rect boundingRect ( const CvSeq* contour )
{
// Points initialization
Point min ( std::numeric_limits<int>::max(),std::numeric_limits<int>::max() );
Point max ( std::numeric_limits<int>::min(),std::numeric_limits<int>::min() );
Â
// Getting bounding box coordinates
for( int i=0; i<contour->total; ++i )
{
CvPoint* p = CV_GET_SEQ_ELEM( CvPoint, contour, i );
printf(" (%d,%d)n", p->x, p->y );
if ( p->x > max.x ) max.x=p->x;
if ( p->x < min.x ) min.x=p->x;
Â
if ( p->y > max.y ) max.y=p->y;
if ( p->y < min.y ) min.y=p->y;
}
Â
Â
return Rect ( min.x,min.y,max.x-min.x+1,max.y-min.y+1 );
}
Â
int main(int argc, char * argv[])
{
vector<vector<Point> > v;
g_image = cvLoadImage( "sample1.jpg" );
cvNamedWindow( "Contours", 1 );
//cvCreateTrackbar( "Threshold", "Contours", &g_thresh, 255, on_trackbar );
//on_trackbar(0);
if( g_storage == NULL )
{
g_gray = cvCreateImage( cvGetSize( g_image ), 8, 1 );
g_storage = cvCreateMemStorage(0);
}
else
{
cvClearMemStorage( g_storage );
}
Â
CvSeq* contours = 0;
cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, 160, 255, CV_THRESH_BINARY );
cvFindContours( g_gray, g_storage, &contours);
cvZero( g_gray );
if( contours)
{
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100 );
}
cvShowImage( "Contours", g_gray );
int size = 0;
int i=0;
CvSeq* max;
for(CvSeq* c=contours; c!=NULL; c=c->h_next )
{
printf("Size of %d contour : %dn",i,c->total);
if((c->total)>size)
{
size=c->total;
max=c;
}
i++;
}
printf("Size of %d contour : %dn",i,max->total);
Rect rect = boundingRect(max);
Point pt1, pt2;
pt1.x = rect.x;
pt1.y = rect.y;
pt2.x = rect.x + rect.width;
pt2.y = rect.y + rect.height;
// Draws the rect in the original image and show it
Â
cvRectangle(g_image, pt1, pt2, CV_RGB(255,0,0), 1);
Â
cvNamedWindow( "Ejemplo", CV_WINDOW_AUTOSIZE );
imshow("Ejemplo", g_image );
cvWaitKey();
Â
return 0;
}
Â
Â
Please help. I have included all libraries and set the path for search directories