Exemplo n.º 1
0
//--------------------------------------------------------------------------------
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";
	}
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------
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");
	
	}
	
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------
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");
    }

}
Exemplo n.º 4
0
//--------------------------------------------------------------------------------
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";
	}
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------
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";
    }
}
Exemplo n.º 6
0
void ofxCvOpticalFlowLK::calc( ofxCvGrayscaleImage & pastImage,
							  ofxCvGrayscaleImage & currentImage,					   
							  int size
							  )
{
	cvCalcOpticalFlowLK( pastImage.getCvImage(), currentImage.getCvImage(),
						cvSize( size, size), vel_x, vel_y );
}
void ofCvOpticalFlowBM::calc( ofxCvGrayscaleImage & pastImage,
                              ofxCvGrayscaleImage & currentImage,
                              int size
                            )
{

    cvCalcOpticalFlowBM(pastImage.getCvImage(), currentImage.getCvImage(),
                        block, shift, max_range, 0, vel_x, vel_y);
}
Exemplo n.º 8
0
//--------------------------------------------------------------------------------
void ofxCvColorImage::convertToGrayscalePlanarImages(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 )
    {
        cvCvtPixToPlane(cvImage, red.getCvImage(), green.getCvImage(), blue.getCvImage(), NULL);
	} else {
        ofLog(OF_LOG_ERROR, "in convertToGrayscalePlanarImages, images are different sizes");
	}     
}
Exemplo n.º 9
0
//--------------------------------------------------------------------------------
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");
	}     
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------
void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom,
                                   ofxCvGrayscaleImage& dad ) {
    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 DepthHoleFiller::performProperClose		  ( ofxCvGrayscaleImage &input, int diameter){
	
	// http://homepages.inf.ed.ac.uk/rbf/HIPR2/close.htm 
	// Defined as Max(f, O(C(O(f))))
	
	ofxCv8uC1_Temp1 = input; // temp copy of original
	
	performMorphologicalOpen	(input, diameter);
	performMorphologicalClose	(input, diameter);
	performMorphologicalOpen	(input, diameter);
	
	cvMax(input.getCvImage(), 
		  ofxCv8uC1_Temp1.getCvImage(), 
		  input.getCvImage());
}
Exemplo n.º 12
0
//--------------------------------------------------------------------------------
void ofxCvColorImage::setFromGrayscalePlanarImages( ofxCvGrayscaleImage& red, ofxCvGrayscaleImage& green, ofxCvGrayscaleImage& blue){
	ofRectangle roi = getROI();
    ofRectangle redRoi = red.getROI();
    ofRectangle greenRoi = green.getROI();
    ofRectangle blueRoi = blue.getROI();
    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 )
    {
         cvCvtPlaneToPix(red.getCvImage(), green.getCvImage(), blue.getCvImage(),NULL, cvImage);
         flagImageChanged();
	} else {
        ofLog(OF_LOG_ERROR, "in setFromGrayscalePlanarImages, ROI/size mismatch");
	}
}
Exemplo n.º 13
0
// Set Pixel Data - Arrays
//--------------------------------------------------------------------------------
void ofxCvFloatImage::operator =	( ofxCvGrayscaleImage& mom ) {
	if( mom.width == width && mom.height == height ) {
        cvConvert( mom.getCvImage(), cvImage );
	} else {
        cout << "error in =, images are different sizes" << endl;
	}
}
Exemplo n.º 14
0
//--------------------------------------------------------------------------------
void ofxCvColorImage::operator =	( ofxCvGrayscaleImage& mom ) {
	if( mom.width == width && mom.height == height ) {
		cvCvtColor( mom.getCvImage(), cvImage, CV_GRAY2RGB );
	} else {
        cout << "error in =, images are different sizes" << endl;
	}
}
Exemplo n.º 15
0
//----------------------------------------------------------------------------------
void ofxCvBlobFinder::findBlobs(ofxCvGrayscaleImage image, bool find_holes) {
    
    CvMemStorage *stor = cvCreateMemStorage();
    IplImage *img = image.getCvImage();
    CvSeq *contours;
    
    _width = img->width;
    _height = img->height;
    
    // CV_RETR_EXTERNAL to not find holes
    int mode = (find_holes)?CV_RETR_LIST:CV_RETR_EXTERNAL;
    
    cvFindContours(img, stor, &contours, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE);
    
    blobz.clear();
    while (contours) {
        ofxCvComplexBlob b =  ofxCvComplexBlob(contours);
        b.setApproxFactor(approxFactor);
        b.getApproxPoints();
        b.getHullPoints();
        blobz.push_back( b );
        contours = contours->h_next;
    }
    
    // sort blobs
    sort(blobz.begin(),  blobz.end(), sort_blob_func);
}
Exemplo n.º 16
0
//--------------------------------------------------------------------------------
void ofxCvColorImage::convertToGrayscalePlanarImages(ofxCvGrayscaleImage& red, ofxCvGrayscaleImage& green, ofxCvGrayscaleImage& blue){
    ofRectangle roi = getROI();
    ofRectangle redRoi = red.getROI();
    ofRectangle greenRoi = green.getROI();
    ofRectangle blueRoi = blue.getROI();
	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 {
        ofLog(OF_LOG_ERROR, "in convertToGrayscalePlanarImages, ROI/size mismatch");
	}
}
Exemplo n.º 17
0
//--------------------------------------------------------------------------------
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");
    }
}
Exemplo n.º 18
0
//--------------------------------------------------------------------------------
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 DepthHoleFiller::updatePreProcessingDepthHistory ( ofxCvGrayscaleImage ofxCv8uC1_DepthRawThreshed ){
	
	if (nDepthHistory > 0){
		for (int i=(nDepthHistory-1); i>0; i--){
			int olderId = i;
			int newerId = i-1;
			cvCopy(ofxCv8uC1_DepthHistory[newerId].getCvImage(), ofxCv8uC1_DepthHistory[olderId].getCvImage(), NULL);
		}
		cvCopy(ofxCv8uC1_DepthRawThreshed.getCvImage(), ofxCv8uC1_DepthHistory[0].getCvImage(), NULL);
	}
}
Exemplo n.º 20
0
//--------------------------------------------------------------------------------
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");
    }
}
Exemplo n.º 21
0
void ofxOpticalFlow::calc(ofxCvGrayscaleImage& prevFrame, ofxCvGrayscaleImage& currentFrame){
	int cornerCount = MAX_CORNERS;
	cvGoodFeaturesToTrack(prevFrame.getCvImage(), eigImg, tempImg, cornersPrev, &cornerCount, 0.01, 5.0, 0, 3, 0, 0.04);
	
	cvFindCornerSubPix(prevFrame.getCvImage(), cornersPrev, cornerCount, 
					   windowSize, cvSize(-1,-1), 
					   cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 20, 0.03));
	
	cvCalcOpticalFlowPyrLK(prevFrame.getCvImage(), currentFrame.getCvImage(), pyrPrev, 
						   pyrCurr, cornersPrev, cornersCurr, cornerCount, windowSize, 
						   5, featuresFound, NULL,
						   cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 20, 0.03), 0);
	
	flowPoints.clear();
	for(int i=0; i<cornerCount; i++){
		if(featuresFound[i] == 0){
			continue;
		}
		flowPoints.push_back(ofxCvFlowPoint(cornersPrev[i].x, cornersPrev[i].y, cornersCurr[i].x, cornersCurr[i].y));
	}
}
Exemplo n.º 22
0
//--------------------------------------------------------------------------------
void ofxCvColorImage::setFromGrayscalePlanarImages( ofxCvGrayscaleImage& red, ofxCvGrayscaleImage& green, ofxCvGrayscaleImage& blue){
	ofRectangle roi = getROI();
    ofRectangle redRoi = red.getROI();
    ofRectangle greenRoi = green.getROI();
    ofRectangle blueRoi = blue.getROI();
	
	if( !bAllocated ){
		ofLogNotice("ofxCvColorImage") << "setFromGrayscalePlanarImages(): allocating to match dimensions";		
		allocate(red.getWidth(), red.getHeight());
	}
	
    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 )
    {
         cvCvtPlaneToPix(red.getCvImage(), green.getCvImage(), blue.getCvImage(),NULL, cvImage);
         flagImageChanged();
	} else {
        ofLogError("ofxCvColorImage") << "setFromGrayscalePlanarImages(): image size or region of interest mismatch";
	}
}
//--------------------------------------------------------------
void DepthHoleFiller::fillHolesUsingContourFinder (ofxCvGrayscaleImage &depthImage, 
												   int maxContourArea, 
												   int maxNContours ){
	
	// Find just the holes, as geometric contours.
	computeBlobContours (depthImage, maxContourArea, maxNContours);
	
	// Rasterize those holes as filled polys, white on a black background.
	computeBlobImage();
	
	// Re-color the blobs with graylevels interpolated from the depth image.
	fillBlobsWithInterpolatedData (depthImage);
	
	// Add the interpolated holes back into the depth image
	cvMax(depthImage.getCvImage(), 
		  ofxCv8uC1_Blobs.getCvImage(), 
		  depthImage.getCvImage());
	
	// Flag changes to the images. 
	ofxCv8uC1_Blobs.flagImageChanged();
	depthImage.flagImageChanged();
}
Exemplo n.º 24
0
//--------------------------------------------------------------------------------
void ofxCvFloatImage::addWeighted( ofxCvGrayscaleImage& mom, float f ) {
	if( mom.width == width && mom.height == height ) {
         IplImage* cvTemp = cvCreateImage( cvSize(width,height), IPL_DEPTH_32F, 1 );
         
		 cvConvertScale( mom.getCvImage(), cvTemp, 1, 0 );
		 //cvConvert( mom.getCvImage(), cvImage ); 
         cvAddWeighted( cvTemp, f, cvImage, 1.0f-f,0, cvImageTemp );
         swapTemp();
         cvReleaseImage( &cvTemp );
    } else {
        cout << "error in addWeighted, images are different sizes" << endl;
    }
}
Exemplo n.º 25
0
//---------------------------------------------------------------------------------
// useful for checking for occlusion, etc with another image
// (via image arithmatic. &= etc)
void videoBlob::draw(ofxCvGrayscaleImage &mom, int color){

	if (nPts > 0 ){
	   CvPoint * ptsTemp = new CvPoint[nPts];
	   for (int i = 0; i < nPts ; i++){
	           ptsTemp[i].x = pts[i].x;
	           ptsTemp[i].y = pts[i].y;
	   }
	   cvFillPoly( mom.getCvImage(), &ptsTemp, &(nPts),1,
	           CV_RGB(color,color,color));
	   delete ptsTemp;

	}
}
//--------------------------------------------------------------
void DepthHoleFiller::fillHolesUsingHistory(ofxCvGrayscaleImage &ofxCv8uC1_Depth){
	
	for (int i=1; i<nDepthHistory; i++){
		
		// get all currently non-valid pixels.
		// note that ofxCv8uC1_Depth gets more and more filled with each iteration. 
		bool bInvert = true;
		int FIRST_VALID_VALUE = 1;
		ofxCv8uC1_DepthInvalid = ofxCv8uC1_Depth;
		ofxCv8uC1_DepthInvalid.threshold(FIRST_VALID_VALUE, bInvert);
		
		// And them with the previous frame, to extract
		// those pixels from the previous frame which are invalid in the current one
		cvAnd(ofxCv8uC1_DepthInvalid.getCvImage(), 
			  ofxCv8uC1_DepthHistory[i].getCvImage(), 
			  ofxCv8uC1_DepthInvalid.getCvImage(), NULL);
		
		// Add them in together
		cvOr (ofxCv8uC1_Depth.getCvImage(), 
			  ofxCv8uC1_DepthInvalid.getCvImage(), 
			  ofxCv8uC1_Depth.getCvImage(), NULL);
	}
}
Exemplo n.º 27
0
//--------------------------------------------------------------------------------
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");
    }
}
Exemplo n.º 28
0
//--------------------------------------------------------------------------------
void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom ){
	if( !mom.bAllocated ){
		ofLog(OF_LOG_ERROR, "in absDiff, mom needs to be allocated");	
		return;	
	}
	if( !bAllocated ){
		ofLog(OF_LOG_NOTICE, "in absDiff, allocating to match dimensions");			
		allocate(mom.getWidth(), mom.getHeight());
	}	

    if( matchingROI(getROI(), mom.getROI()) ) {
        cvAbsDiff( cvImage, mom.getCvImage(), cvImageTemp );
        swapTemp();
        flagImageChanged();
    } else {
        ofLog(OF_LOG_ERROR, "in *=, ROI mismatch");
    }
}
Exemplo n.º 29
0
//--------------------------------------------------------------
void testApp::computeDepthHistogram (ofxCvGrayscaleImage depthImage) {
    // Compute the histogram of the depth-colored difference-from-background image.

    IplImage*  iplDepthImg = depthImage.getCvImage();
    cvCalcHist( &iplDepthImg, depthHistogram, 0, NULL );
    float *depthHistArr = cvGetHistValue_1D (depthHistogram, 0);

    int maxVal = 0;
    int startIndex = 1; // don't count black pixels.
    for (int i=startIndex; i<depthHistogramSize; i++) {
        if (depthHistArr[i] > maxVal) {
            maxVal = depthHistArr[i];
        }
    }

    for (int i=0; i<depthHistogramSize; i++) {
        depthHistogramData[i] = depthHistArr[i] / (float)maxVal;
    }
}
Exemplo n.º 30
0
//--------------------------------------------------------------------------------
void ofxCvGrayscaleImage::absDiff( ofxCvGrayscaleImage& mom ){
	if( !mom.bAllocated ){
		ofLogError("ofxCvGrayscaleImage") << "absDiff(): source image not allocated";
		return;	
	}
	if( !bAllocated ){
		ofLogNotice("ofxCvGrayscaleImage") << "absDiff(): allocating to match dimensions: "
			<< mom.getWidth() << " " << mom.getHeight();
		allocate(mom.getWidth(), mom.getHeight());
	}	

    if( matchingROI(getROI(), mom.getROI()) ) {
        cvAbsDiff( cvImage, mom.getCvImage(), cvImageTemp );
        swapTemp();
        flagImageChanged();
    } else {
        ofLogError("ofxCvGrayscaleImage") << "absDiff(): region of interest mismatch";
    }
}