//-------------------------------------------------------------------------------- void ofxCvColorImage::operator = ( const ofxCvShortImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvShortImage& mom = const_cast<ofxCvShortImage&>(_mom); if( mom.getWidth() == 0 || mom.getHeight() == 0 ){ ofLogError("ofxCvColorImage") << "operator=: source width and/or height are zero:" << mom.getWidth() << " " << mom.getHeight(); return; } if( !bAllocated ){ ofLogNotice("ofxCvColorImage") << "operator=: allocating to match dimensions: " << mom.getWidth() << " " << mom.getHeight(); allocate(mom.getWidth(), mom.getHeight()); } if( matchingROI(getROI(), mom.getROI()) ) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } ofRectangle roi = getROI(); setImageROI(cvGrayscaleImage, roi); rangeMap( mom.getCvImage(), cvGrayscaleImage, 0, 65535.0f, 0, 255.0f ); cvCvtColor( cvGrayscaleImage, cvImage, CV_GRAY2RGB ); flagImageChanged(); } else { ofLogError("ofxCvColorImage") << "operator=: region of interest mismatch"; } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::operator = ( const ofxCvColorImage& _mom ) { // cast non-const, no worries, we will reverse any chages ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( mom.getWidth() == 0 || mom.getHeight() == 0 ){ ofLog(OF_LOG_ERROR, "in =, mom width or height is 0"); return; } if( !bAllocated ){ ofLog(OF_LOG_NOTICE, "in =, allocating to match dimensions"); allocate(mom.getWidth(), mom.getHeight()); } if( matchingROI(getROI(), mom.getROI()) ) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } ofRectangle roi = getROI(); setImageROI(cvGrayscaleImage, roi); cvCvtColor( mom.getCvImage(), cvGrayscaleImage, CV_RGB2GRAY ); convertGrayToFloat(cvGrayscaleImage, cvImage); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------- void ofxCvGrayscaleAdvanced::swapTemp() { if (getROI().x != 0 || getROI().y != 0 || getROI().width != cvImage->width || getROI().height != cvImage->height ){ cvCopy( cvImageTemp, cvImage ); } else { IplImage* temp; temp = cvImage; cvImage = cvImageTemp; cvImageTemp = temp; } }
//-------------------------------------------------------------------------------- void ofxCvImage::swapTemp() { if (getROI().x != 0 || getROI().y != 0 || getROI().width != width || getROI().height != height ) { cvCopy( cvImageTemp, cvImage ); } else { IplImage* temp; temp = cvImage; cvImage = cvImageTemp; cvImageTemp = temp; } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::setRoiFromPixels( const unsigned char* _pixels, int w, int h ) { if( w == 0 || h == 0 ){ ofLogError("ofxCvColorImage") << "setRoiFromPixels(): width and height are zero"; return; } if(!bAllocated){ ofLogError("ofxCvColorImage") << "setRoiFromPixels(): image not allocated"; return; } ofRectangle roi = getROI(); ofRectangle inputROI = ofRectangle( roi.x, roi.y, w, h); ofRectangle iRoi = getIntersectionROI( roi, inputROI ); if( iRoi.width > 0 && iRoi.height > 0 ) { // copy pixels from _pixels, however many we have or will fit in cvImage for( int i=0; i < iRoi.height; i++ ) { memcpy( cvImage->imageData + ((i+(int)iRoi.y)*cvImage->widthStep) + (int)iRoi.x*3, _pixels + (i*w*3), (int)(iRoi.width*3) ); } flagImageChanged(); } else { ofLogError("ofxCvColorImage") << "setRoiFromPixels(): region of interest width and/or height are zero: " << iRoi.width << " " << iRoi.height; } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::convertToGrayscalePlanarImage (ofxCvGrayscaleImage& grayImage, int whichPlane){ ofRectangle roi = getROI(); ofRectangle grayRoi = grayImage.getROI(); if( grayRoi.width == roi.width && grayRoi.height == roi.height ){ switch (whichPlane){ case 0: cvCvtPixToPlane(cvImage, grayImage.getCvImage(), NULL, NULL, NULL); grayImage.flagImageChanged(); break; case 1: cvCvtPixToPlane(cvImage, NULL, grayImage.getCvImage(), NULL, NULL); grayImage.flagImageChanged(); break; case 2: cvCvtPixToPlane(cvImage, NULL, NULL, grayImage.getCvImage(), NULL); grayImage.flagImageChanged(); break; } } else { ofLog(OF_LOG_ERROR, "in convertToGrayscalePlanarImages, ROI/size mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::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()) ) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } ofRectangle roi = getROI(); setImageROI(cvGrayscaleImage, roi); rangeMap( mom.getCvImage(), cvGrayscaleImage, 0, 65535.0f, 0, 255.0f ); cvCvtColor( cvGrayscaleImage, cvImage, CV_GRAY2RGB ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- int ofxCvImage::countNonZeroInRegion( int x, int y, int w, int h ) { //TODO: test this method if (w == 0 || h == 0) return 0; int count = 0; // intersect the global ROI with the region to check ofRectangle iRoi = getIntersectionROI( getROI(), ofRectangle(x,y,w,h) ); ofRectangle lastROI = getROI(); setROI(iRoi); count = cvCountNonZero( cvImage ); setROI(lastROI); return count; }
//-------------------------------------------------------------------------------- float* ofxCvFloatImage::getRoiPixelsAsFloats(){ if(bFloatPixelsDirty) { ofRectangle roi = getROI(); if(floatPixels == NULL) { // we need pixels, allocate it floatPixels = new float[(int)(roi.width*roi.height)]; floatPixelsW = roi.width; floatPixelsH = roi.height; } else if(floatPixelsW != roi.width || floatPixelsH != roi.height) { // ROI changed, reallocate floatPixels for new size delete floatPixels; floatPixels = new float[(int)(roi.width*roi.height)]; floatPixelsW = roi.width; floatPixelsH = roi.height; } // copy from ROI to pixels for( int i = 0; i < roi.height; i++ ) { memcpy( floatPixels + (int)(i*roi.width), cvImage->imageData + ((int)(i+roi.y)*cvImage->widthStep) + (int)roi.x*sizeof(float), roi.width*sizeof(float) ); } bFloatPixelsDirty = false; } return floatPixels; }
//-------------------------------------------------------------------------------- unsigned char* ofxCvFloatImage::getRoiPixels(){ if(bPixelsDirty) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } ofRectangle roi = getROI(); setImageROI(cvGrayscaleImage, roi); //make sure ROI is in sync convertFloatToGray(cvImage, cvGrayscaleImage); if(pixels == NULL) { // we need pixels, allocate it pixels = new unsigned char[(int)(roi.width*roi.height)]; pixelsWidth = roi.width; pixelsHeight = roi.height; } else if(pixelsWidth != roi.width || pixelsHeight != roi.height) { // ROI changed, reallocate pixels for new size delete pixels; pixels = new unsigned char[(int)(roi.width*roi.height)]; pixelsWidth = roi.width; pixelsHeight = roi.height; } // copy from ROI to pixels for( int i = 0; i < roi.height; i++ ) { memcpy( pixels + (int)(i*roi.width), cvGrayscaleImage->imageData + ((int)(i+roi.y)*cvGrayscaleImage->widthStep) + (int)roi.x, roi.width ); } bPixelsDirty = false; } return pixels; }
//-------------------------------------------------------------------------------- unsigned char* ofxCvFloatImage::getPixels(){ if(bPixelsDirty) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } ofRectangle lastROI = getROI(); resetImageROI(cvGrayscaleImage); convertFloatToGray(cvImage, cvGrayscaleImage); setROI(lastROI); if(pixels == NULL) { // we need pixels, allocate it pixels = new unsigned char[width*height]; pixelsWidth = width; pixelsHeight = height; } else if(pixelsWidth != width || pixelsHeight != height) { // ROI changed, reallocate pixels for new size delete pixels; pixels = new unsigned char[width*height]; pixelsWidth = width; pixelsHeight = height; } // copy from ROI to pixels for( int i = 0; i < height; i++ ) { memcpy( pixels + (i*width), cvGrayscaleImage->imageData + (i*cvGrayscaleImage->widthStep), width ); } bPixelsDirty = false; } return pixels; }
//-------------------------------------------------------------------------------- void ofxCvColorImage::operator = ( const ofxCvColorImage& _mom ) { if(this != &_mom) { //check for self-assignment // cast non-const, no worries, we will reverse any changes ofxCvColorImage& mom = const_cast<ofxCvColorImage&>(_mom); if( mom.getWidth() == 0 || mom.getHeight() == 0 ){ ofLogError("ofxCvColorImage") << "operator=: source width and/or height are zero:" << mom.getWidth() << " " << mom.getHeight(); return; } if( !bAllocated ){ ofLogNotice("ofxCvColorImage") << "operator=: allocating to match dimensions: " << mom.getWidth() << " " << mom.getHeight(); allocate(mom.getWidth(), mom.getHeight()); } if( matchingROI(getROI(), mom.getROI()) ) { cvCopy( mom.getCvImage(), cvImage, 0 ); flagImageChanged(); } else { ofLogError("ofxCvColorImage") << "operator=: region of interest mismatch"; } } else { ofLogWarning("ofxCvColorImage") << "operator=: assigning image to itself, not copying"; } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::convertToGrayscalePlanarImages(ofxCvGrayscaleImage& red, ofxCvGrayscaleImage& green, ofxCvGrayscaleImage& blue){ if( !bAllocated ){ ofLogError("ofxCvColorImage") << "convertToGrayscalePlanarImages(): image not allocated"; return; } ofRectangle roi = getROI(); ofRectangle redRoi = red.getROI(); ofRectangle greenRoi = green.getROI(); ofRectangle blueRoi = blue.getROI(); if( !red.bAllocated ){ red.allocate(width, height); } if( !green.bAllocated ){ green.allocate(width, height); } if( !blue.bAllocated ){ blue.allocate(width, height); } if( redRoi.width == roi.width && redRoi.height == roi.height && greenRoi.width == roi.width && greenRoi.height == roi.height && blueRoi.width == roi.width && blueRoi.height == roi.height ) { cvCvtPixToPlane(cvImage, red.getCvImage(), green.getCvImage(), blue.getCvImage(), NULL); red.flagImageChanged(); green.flagImageChanged(); blue.flagImageChanged(); } else { ofLogError("ofxCvColorImage") << "convertToGrayscalePlanarImages(): image size or region of interest mismatch"; } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::operator = ( const ofxCvFloatImage& _mom ) { if(this != &_mom) { //check for self-assignment // cast non-const, no worries, we will reverse any chages ofxCvFloatImage& mom = const_cast<ofxCvFloatImage&>(_mom); if( mom.getWidth() == 0 || mom.getHeight() == 0 ){ ofLog(OF_LOG_ERROR, "in =, mom width or height is 0"); return; } if( !bAllocated ){ ofLog(OF_LOG_NOTICE, "in =, allocating to match dimensions"); allocate(mom.getWidth(), mom.getHeight()); } if( matchingROI(getROI(), mom.getROI()) ) { if( getNativeScaleMin() == mom.getNativeScaleMin() && getNativeScaleMax() == mom.getNativeScaleMax() ) { cvCopy( mom.getCvImage(), cvImage, 0 ); } else { rangeMap( mom.getCvImage(), cvImage, mom.getNativeScaleMin(), mom.getNativeScaleMax(), getNativeScaleMin(), getNativeScaleMax() ); } flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } } else { ofLog(OF_LOG_WARNING, "in =, you are assigning a ofxCvFloatImage to itself"); } }
//-------------------------------------------------------------------------------- void ofxCvImage::operator *= ( ofxCvImage& mom ) { if( !mom.bAllocated ){ ofLog(OF_LOG_ERROR, "in *=, mom needs to be allocated"); return; } if( !bAllocated ){ ofLog(OF_LOG_NOTICE, "in *=, allocating to match dimensions"); allocate(mom.getWidth(), mom.getHeight()); } if( mom.getCvImage()->nChannels == cvImage->nChannels && mom.getCvImage()->depth == cvImage->depth ) { if( matchingROI(getROI(), mom.getROI()) ) { float scalef = 1.0f / 255.0f; cvMul( cvImage, mom.getCvImage(), cvImageTemp, scalef ); swapTemp(); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in *=, ROI mismatch"); } } else { ofLog(OF_LOG_ERROR, "in *=, images need to have matching type"); } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::setRoiFromPixels( float* _pixels, int w, int h ) { if( w == 0 || h == 0 ){ ofLog(OF_LOG_ERROR, "in setFromPixels, w and h cannot = 0"); return; } if(!bAllocated){ ofLog(OF_LOG_ERROR, "in setRoiFromPixels, image is not allocated"); return; } ofRectangle roi = getROI(); ofRectangle inputROI = ofRectangle( roi.x, roi.y, w, h); ofRectangle iRoi = getIntersectionROI( roi, inputROI ); if( iRoi.width > 0 && iRoi.height > 0 ) { // copy _pixels into cvImage for( int i=0; i < iRoi.height; i++ ) { memcpy( cvImage->imageData + ((i+(int)iRoi.y)*cvImage->widthStep) + (int)iRoi.x*sizeof(float), _pixels + (i*w), (int)(iRoi.width*sizeof(float)) ); } flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in setRoiFromPixels, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::setFromPixels( const unsigned char* _pixels, int w, int h ) { // This sets the internal image ignoring any ROI if( w == 0 || h == 0 ){ ofLog(OF_LOG_ERROR, "in setFromPixels, w and h cannot = 0"); return; } if( !bAllocated || w != width || h != height ) { ofLog(OF_LOG_NOTICE, "in setFromPixels, reallocating to match dimensions"); allocate(w,h); } if( w == width && h == height ) { ofRectangle lastROI = getROI(); if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } resetImageROI(cvGrayscaleImage); // copy _pixels into cvGrayscaleImage for( int i=0; i < height; i++ ) { memcpy( cvGrayscaleImage->imageData + (i*cvGrayscaleImage->widthStep), _pixels + (i*w), width ); } convertGrayToFloat(cvGrayscaleImage, cvImage); setROI(lastROI); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in setFromPixels, size mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::setRoiFromPixels( const unsigned char* _pixels, int w, int h ) { if( w == 0 || h == 0 ){ ofLog(OF_LOG_ERROR, "in setFromPixels, w and h cannot = 0"); return; } if(!bAllocated){ ofLog(OF_LOG_ERROR, "in setRoiFromPixels, image is not allocated"); return; } ofRectangle roi = getROI(); ofRectangle inputROI = ofRectangle( roi.x, roi.y, w, h); ofRectangle iRoi = getIntersectionROI( roi, inputROI ); if( iRoi.width > 0 && iRoi.height > 0 ) { if( cvGrayscaleImage == NULL ) { cvGrayscaleImage = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 1 ); } setImageROI(cvGrayscaleImage, roi); //make sure ROI is in sync // copy _pixels into cvGrayscaleImage for( int i=0; i < iRoi.height; i++ ) { memcpy( cvGrayscaleImage->imageData + ((i+(int)iRoi.y)*cvGrayscaleImage->widthStep) + (int)iRoi.x, _pixels + (i*w), (int)(iRoi.width) ); } convertGrayToFloat(cvGrayscaleImage, cvImage); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in setRoiFromPixels, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom, ofxCvGrayscaleImage& dad ) { if( !mom.bAllocated ){ ofLog(OF_LOG_ERROR, "in absDiff, mom needs to be allocated"); return; } if( !dad.bAllocated ){ ofLog(OF_LOG_ERROR, "in absDiff, dad needs to be allocated"); return; } if( !bAllocated ){ ofLog(OF_LOG_NOTICE, "in absDiff, allocating to match dimensions"); allocate(mom.getWidth(), mom.getHeight()); } ofRectangle roi = getROI(); ofRectangle momRoi = mom.getROI(); ofRectangle dadRoi = dad.getROI(); if( (momRoi.width == roi.width && momRoi.height == roi.height ) && (dadRoi.width == roi.width && dadRoi.height == roi.height ) ) { cvAbsDiff( mom.getCvImage(), dad.getCvImage(), cvImage ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in absDiff, images are different sizes"); } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::setRoiFromPixels( const unsigned char* _pixels, int w, int h ) { if( w == 0 || h == 0 ){ ofLog(OF_LOG_ERROR, "in setFromPixels, w and h cannot = 0"); return; } if(!bAllocated){ ofLog(OF_LOG_ERROR, "in setRoiFromPixels, image is not allocated"); return; } ofRectangle roi = getROI(); ofRectangle inputROI = ofRectangle( roi.x, roi.y, w, h); ofRectangle iRoi = getIntersectionROI( roi, inputROI ); if( iRoi.width > 0 && iRoi.height > 0 ) { // copy pixels from _pixels, however many we have or will fit in cvImage for( int i=0; i < iRoi.height; i++ ) { memcpy( cvImage->imageData + ((i+(int)iRoi.y)*cvImage->widthStep) + (int)iRoi.x, _pixels + (i*w), (int)(iRoi.width)); } flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in setRoiFromPixels, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvImage::operator &= ( ofxCvImage& mom ) { if( !mom.bAllocated ){ ofLogError("ofxCvImage") << "operator&=: source image not allocated"; return; } if( !bAllocated ){ ofLogNotice("ofxCvImage") << "operator&=: allocating to match dimensions: " << mom.getWidth() << " " << mom.getHeight(); allocate(mom.getWidth(), mom.getHeight()); } if( mom.getCvImage()->nChannels == cvImage->nChannels && mom.getCvImage()->depth == cvImage->depth ) { if( matchingROI(getROI(), mom.getROI()) ) { cvAnd( cvImage, mom.getCvImage(), cvImageTemp ); swapTemp(); flagImageChanged(); } else { ofLogError("ofxCvImage") << "operator&=: region of interest mismatch"; } } else { ofLogError("ofxCvImage") << "operator&=: images need to have matching type"; } }
//-------------------------------------------------------------------------------- unsigned char* ofxCvGrayscaleImage::getRoiPixels() { if(bPixelsDirty) { ofRectangle roi = getROI(); if(pixels == NULL) { // we need pixels, allocate it pixels = new unsigned char[(int)(roi.width*roi.height)]; pixelsWidth = (int)roi.width; pixelsHeight = (int)roi.height; } else if(pixelsWidth != roi.width || pixelsHeight != roi.height) { // ROI changed, reallocate pixels for new size delete pixels; pixels = new unsigned char[(int)(roi.width*roi.height)]; pixelsWidth = (int)roi.width; pixelsHeight = (int)roi.height; } // copy from ROI to pixels for( int i = 0; i < roi.height; i++ ) { memcpy( pixels + (int)(i*roi.width), cvImage->imageData + ((int)(i+roi.y)*cvImage->widthStep) + (int)roi.x, (int)roi.width ); } bPixelsDirty = false; } return pixels; }
//-------------------------------------------------------------------------------- void ofxCvImage::operator *= ( ofxCvImage& mom ) { if( !mom.bAllocated ){ ofLogError("ofxCvImage") << "operator*=: mom needs to be allocated"; return; } if( !bAllocated ){ ofLogNotice("ofxCvImage") << "operator*=: allocating to match dimensions: " << mom.getWidth() << " " << mom.getHeight(); allocate(mom.getWidth(), mom.getHeight()); } if( mom.getCvImage()->nChannels == cvImage->nChannels && mom.getCvImage()->depth == cvImage->depth ) { if( matchingROI(getROI(), mom.getROI()) ) { float scalef = 1.0f / 255.0f; cvMul( cvImage, mom.getCvImage(), cvImageTemp, scalef ); swapTemp(); flagImageChanged(); } else { ofLogError("ofxCvImage") << "operator*=: region of interest mismatch"; } } else { ofLogError("ofxCvImage") << "operator*=: images type mismatch"; } }
//-------------------------------------------------------------------------------- void ofxCvColorImage::convertToGrayscalePlanarImage (ofxCvGrayscaleImage& grayImage, int whichPlane){ if( !bAllocated ){ ofLogError("ofxCvColorImage") << "convertToGrayscalePlanarImage(): image not allocated"; return; } if( !grayImage.bAllocated ){ grayImage.allocate(width, height); } ofRectangle roi = getROI(); ofRectangle grayRoi = grayImage.getROI(); if( grayRoi.width == roi.width && grayRoi.height == roi.height ){ switch (whichPlane){ case 0: cvCvtPixToPlane(cvImage, grayImage.getCvImage(), NULL, NULL, NULL); grayImage.flagImageChanged(); break; case 1: cvCvtPixToPlane(cvImage, NULL, grayImage.getCvImage(), NULL, NULL); grayImage.flagImageChanged(); break; case 2: cvCvtPixToPlane(cvImage, NULL, NULL, grayImage.getCvImage(), NULL); grayImage.flagImageChanged(); break; } } else { ofLogError("ofxCvColorImage") << "convertToGrayscalePlanarImages(): image size or region of interest mismatch"; } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom, ofxCvGrayscaleImage& dad ) { if( !mom.bAllocated ){ ofLogError("ofxCvGrayscaleImage") << "absDiff(): first source image (mom) not allocated"; return; } if( !dad.bAllocated ){ ofLogError("ofxCvGrayscaleImage") << "absDiff(): second source image (dad) not allocated"; return; } if( !bAllocated ){ ofLogNotice("ofxCvGrayscaleImage") << "absDiff(): allocating to match dimensions: " << mom.getWidth() << " " << mom.getHeight(); allocate(mom.getWidth(), mom.getHeight()); } ofRectangle roi = getROI(); ofRectangle momRoi = mom.getROI(); ofRectangle dadRoi = dad.getROI(); if( (momRoi.width == roi.width && momRoi.height == roi.height ) && (dadRoi.width == roi.width && dadRoi.height == roi.height ) ) { cvAbsDiff( mom.getCvImage(), dad.getCvImage(), cvImage ); flagImageChanged(); } else { ofLogError("ofxCvGrayscaleImage") << "absDiff(): source image size mismatch between first (mom) & second (dad) image"; } }
//-------------------------------------------------------------------------------- void ofxCvGrayscaleImage::setFromCvColorImage( ofxCvColorImage& mom ) { if( matchingROI(getROI(), mom.getROI()) ) { cvCvtColor( mom.getCvImage(), cvImage, CV_RGB2GRAY ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in =, ROI mismatch"); } }
//-------------------------------------------------------------------------------- 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 ofxCvFloatImage::addWeighted( ofxCvGrayscaleImage& mom, float f ) { if( matchingROI(getROI(), mom.getROI()) ) { convertGrayToFloat(mom.getCvImage(), cvImageTemp); cvAddWeighted( cvImageTemp, f, cvImage, 1.0f-f,0, cvImage ); flagImageChanged(); } else { ofLog(OF_LOG_ERROR, "in addWeighted, ROI mismatch"); } }
//-------------------------------------------------------------------------------- void ofxCvFloatImage::operator *= ( float scalar ){ ofRectangle roi = getROI(); for( int i=0; i<roi.height; i++ ) { float* ptr = (float*)(cvImage->imageData + (int)(i+roi.y)*cvImage->widthStep); for( int j=0; j<roi.width; j++ ) { ptr[(int)(j+roi.x)] *= scalar; } } }
//-------------------------------------------------------------------------------- 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"); } }