#include "cvContourToImage.h" cvContourToImage::cvContourToImage(int _w, int _h){ w = _w; h = _h; image = cvCreateImage( cvSize( _w,_h ), IPL_DEPTH_8U, 1 ); storage = NULL; } //------------------------------------------------------------------------------------- cvContourToImage::~cvContourToImage() { } //------------------------------------------------------------------------------------- void cvContourToImage::setup(int _w, int _h){ w = _w; h = _h; bAllocated = false; image = cvCreateImage( cvSize( _w,_h ), IPL_DEPTH_8U, 1 ); storage = NULL; } //------------------------------------------------------------------------------------- IplImage * cvContourToImage::convertQuadToImage( ofPoint2f fQuad[4] ) { // get storage storage = cvCreateMemStorage(); CvPoint cPts[4]; cPts[0].x = (int)fQuad[0].x; cPts[0].y = (int)fQuad[0].y; cPts[1].x = (int)fQuad[1].x; cPts[1].y = (int)fQuad[1].y; cPts[2].x = (int)fQuad[2].x; cPts[2].y = (int)fQuad[2].y; cPts[3].x = (int)fQuad[3].x; cPts[3].y = (int)fQuad[3].y; int nPts = 4; cvSetZero( image ); cvFillConvexPoly( image, (CvPoint*)cPts, nPts, cvScalar(255,255,255,255)); cvReleaseMemStorage(&storage); return image;//(unsigned char*) image->imageData; } //------------------------------------------------------------------------------------- IplImage * cvContourToImage::convertContourToImage( ofPoint2f * pts, int totalPts) { // max contour points should be defined in shared keying header int numRegions = 1; int numInner = 1; int currentRegion = 0; int currentContour = 0; // get storage storage = cvCreateMemStorage(); CvPoint * cPts = new CvPoint[totalPts+1]; // copy points from array for(int i = 0; i < totalPts; i++) { cPts[i].x = pts[i].x; cPts[i].y = pts[i].y; } cPts[totalPts].x = pts[0].x; cPts[totalPts].y = pts[0].y; cvSetZero( image ); CvPoint * cPtss = cPts; //cvFillConvexPoly( image, (CvPoint*)cPtss, totalPts, cvScalar(255,255,255,255)); cvFillPoly( image, &cPtss, &totalPts, 1,cvScalar(255,255,255,255) ); delete cPts; cvReleaseMemStorage(&storage); return image;//(unsigned char*) image->imageData; }