//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom ) { if( matchingROI(getROI(), mom.getROI()) ) { cvAbsDiff( cvImage, mom.getCvImage(), cvImageTemp ); swapTemp(); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in *=, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvImage::operator -= ( float value ) { if( !bAllocated ){ ofLog(OF_LOG_ERROR, "in -=, need to allocate image first"); return; } cvSubS( cvImage, cvScalar(value), cvImageTemp ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::remap( IplImage* mapX, IplImage* mapY ) { if( !bAllocated ){ ofLogError("ofxCvImage") << "remap(): image not allocated"; return; } cvRemap( cvImage, cvImageTemp, mapX, mapY ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::erode(int iterations) { if( !bAllocated ){ ofLogError("ofxCvImage") << "erode(): image not allocated"; return; } cvErode(cvImage, cvImageTemp, 0, iterations); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::operator += ( float value ) { if( !bAllocated ){ ofLogError("ofxCvImage") << "operator-=: image not allocated"; return; } cvAddS( cvImage, cvScalar(value), cvImageTemp ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::blurGaussian( int value ) { if( value % 2 == 0 ) { ofLog(OF_LOG_NOTICE, "in blurGaussian, value not odd -> will add 1 to cover your back"); value++; } cvSmooth( cvImage, cvImageTemp, CV_GAUSSIAN ,value ); swapTemp(); flagImageChanged(); }
// Image Filter Operations //-------------------------------------------------------------------------------- void ofxCvImage::dilate() { if( !bAllocated ){ ofLogError("ofxCvImage") << "dilate(): image not allocated"; return; } cvDilate( cvImage, cvImageTemp, 0, 1 ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::operator = ( const ofxCvColorImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { cvCvtColor( mom.getCvImage(), cvImage, CV_RGB2GRAY ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::operator = ( const ofxCvShortImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvShortImage& mom = const_cast<ofxCvShortImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { rangeMap( mom.getCvImage(), cvImage, 0, 65535.0f, 0, 255.0f ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::threshold( int value, bool invert){ if( !bAllocated ){ ofLogError("ofxCvGrayscaleImage") << "threshold(): image not allocated"; return; } // threshold can be done faster in place int type = invert ? CV_THRESH_BINARY_INV : CV_THRESH_BINARY; cvThreshold(cvImage, cvImage, value, 255, type); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::contrastStretch() { if( !bAllocated ){ ofLogError("ofxCvGrayscaleImage") << "contrastStretch(): image not allocated"; return; } double minVal, maxVal; cvMinMaxLoc( cvImage, &minVal, &maxVal, NULL, NULL, 0 ); rangeMap( cvImage, minVal,maxVal, 0,255 ); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::contrastStretch() { if( !bAllocated ){ ofLog(OF_LOG_ERROR, "in contrastStretch, image is not allocated"); return; } double minVal, maxVal; cvMinMaxLoc( cvImage, &minVal, &maxVal, NULL, NULL, 0 ); rangeMap( cvImage, minVal,maxVal, 0,255 ); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::threshold( int value, bool invert){ if( !bAllocated ){ ofLog(OF_LOG_ERROR, "in threshold, image is not allocated"); return; } // threshold can be done faster in place int type = invert ? CV_THRESH_BINARY_INV : CV_THRESH_BINARY; cvThreshold(cvImage, cvImage, value, 255, type); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::undistort( float radialDistX, float radialDistY, float tangentDistX, float tangentDistY, float focalX, float focalY, float centerX, float centerY ){ float camIntrinsics[] = { focalX, 0, centerX, 0, focalY, centerY, 0, 0, 1 }; float distortionCoeffs[] = { radialDistX, radialDistY, tangentDistX, tangentDistY }; cvUnDistortOnce( cvImage, cvImageTemp, camIntrinsics, distortionCoeffs, 1 ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::setROI( int x, int y, int w, int h ) { x = (int)ofClamp(x, 0, (int)width-1); y = (int)ofClamp(y, 0, (int)height-1); w = (int)ofClamp(w, 0, (int)width - x); h = (int)ofClamp(h, 0, (int)height - y); cvSetImageROI( cvImage, cvRect(x,y, w,h) ); cvSetImageROI( cvImageTemp, cvRect(x,y, w,h) ); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::addWeighted( ofxCvGrayscaleImage& mom, float f ) { if( pushSetBothToTheirIntersectionROI(*this,mom) ) { convertGrayToFloat(mom.getCvImage(), cvImageTemp); cvAddWeighted( cvImageTemp, f, cvImage, 1.0f-f,0, cvImage ); popROI(); //restore prevoius ROI mom.popROI(); //restore prevoius ROI flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in addWeighted, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvImage::operator = ( const IplImage* mom ) { if( mom->width == width && mom->height == height && mom->nChannels == cvImage->nChannels && mom->depth == cvImage->depth ) { cvCopy( mom, cvImage ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, images need to match in size, channels, and depth"); } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::setFromGrayscalePlanarImages( ofxCvGrayscaleImage& red, ofxCvGrayscaleImage& green, ofxCvGrayscaleImage& blue){ if( red.width == width && red.height == height && green.width == width && green.height == height && blue.width == width && blue.height == height ) { cvCvtPlaneToPix(red.getCvImage(), green.getCvImage(), blue.getCvImage(),NULL, cvImage); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in setFromGrayscalePlanarImages, images are different sizes"); } }
//-------------------------------------------------------------------------------- void CPUImageFilter::operator = ( const ofxCvColorImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( pushSetBothToTheirIntersectionROI(*this,mom) ) { cvCvtColor( mom.getCvImage(), cvImage, CV_RGB2GRAY ); popROI(); //restore prevoius ROI mom.popROI(); //restore prevoius ROI flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvColorImageAlpha::operator = ( const ofxCvColorImage& _mom ) { ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { cvCopy( mom.getCvImage(), cvImage, 0 ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::operator = ( const ofxCvGrayscaleImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvGrayscaleImage& mom = const_cast<ofxCvGrayscaleImage&>(_mom); if( pushSetBothToTheirIntersectionROI(*this,mom) ) { convertGrayToFloat(mom.getCvImage(), cvImage); popROI(); //restore prevoius ROI mom.popROI(); //restore prevoius ROI flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void setfilter::operator = ( const ofxCvFloatImage& _mom ) { //-- for using a floatimage --// ofxCvFloatImage& mom = const_cast<ofxCvFloatImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { cvConvert( mom.getCvImage(), cvImage ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void setfilter::operator = ( const ofxCvColorImage& _mom ) { //-- for using a colorimage --// ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { cvCvtColor( mom.getCvImage(), cvImage, CV_RGB2GRAY ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvImage::mirror( bool bFlipVertically, bool bFlipHorizontally ) { int flipMode = 0; if( bFlipVertically && !bFlipHorizontally ) flipMode = 0; else if( !bFlipVertically && bFlipHorizontally ) flipMode = 1; else if( bFlipVertically && bFlipHorizontally ) flipMode = -1; else return; cvFlip( cvImage, cvImageTemp, flipMode ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::blurGaussian( int value ) { if( !bAllocated ){ ofLog(OF_LOG_ERROR, "in blurGaussian, need to allocate image first"); return; } if( value % 2 == 0 ) { ofLog(OF_LOG_NOTICE, "in blurGaussian, value not odd -> will add 1 to cover your back"); value++; } cvSmooth( cvImage, cvImageTemp, CV_GAUSSIAN ,value ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::blurGaussian( int value ) { if( !bAllocated ){ ofLogError("ofxCvImage") << "blurGaussian(): image not allocated"; return; } if( value % 2 == 0 ) { ofLogNotice("ofxCvImage") << "blurGaussian(): value " << value << " not odd, adding 1"; value++; } cvSmooth( cvImage, cvImageTemp, CV_GAUSSIAN ,value ); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::operator = ( const ofxCvGrayscaleImage& _mom ) { if(this != &_mom) { //check for self-assignment // cast non-const, no worries, we will reverse any chages ofxCvGrayscaleImage& mom = const_cast<ofxCvGrayscaleImage&>(_mom); if( matchingROI(getROI(), mom.getROI()) ) { cvCopy( mom.getCvImage(), cvImage, 0 ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } } else { ofLog(OF_LOG_WARNING, "in =, you are assigning a ofxCvGrayscaleImage to itself"); } }
//-------------------------------------------------------------------------------- void ofxCvShortImage::addWeighted( ofxCvGrayscaleImage& mom, float f ) { if( !bAllocated ){ ofLog(OF_LOG_ERROR, "in addWeighted, image is not allocated"); return; } if( matchingROI(getROI(), mom.getROI()) ) { convertGrayToShort(mom.getCvImage(), cvImageTemp); cvAddWeighted( cvImageTemp, f, cvImage, 1.0f-f,0, cvImage ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in addWeighted, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void setfilter::highpass ( float blur01, float blur02 ) { //-- blur original image --// if(blur01 > 0) cvSmooth( cvImage, cvImageTemp, CV_BLUR , (blur01 * 2) + 1); //-- original image - blur image = highpass image --// cvSub( cvImage, cvImageTemp, cvImageTemp ); //-- blur highpass image to remove noise --// if(blur02 > 0) cvSmooth( cvImageTemp, cvImageTemp, CV_BLUR , (blur02 * 2) + 1); swapTemp(); flagImageChanged(); }
//-------------------------------------------------------------------------------- void ofxCvImage::setROI( int x, int y, int w, int h ) { if( !bAllocated ){ ofLogError("ofxCvImage") << "setROI(): image not allocated"; return; } x = (int)ofClamp(x, 0, (int)width-1); y = (int)ofClamp(y, 0, (int)height-1); w = (int)ofClamp(w, 0, (int)width - x); h = (int)ofClamp(h, 0, (int)height - y); cvSetImageROI( cvImage, cvRect(x,y, w,h) ); cvSetImageROI( cvImageTemp, cvRect(x,y, w,h) ); flagImageChanged(); }