#include "cardFinder.h"
	
//------------------------------
cardFinder::cardFinder(){
	
}

//------------------------------
void cardFinder::setup(int width, int height){
	cornerSensitivity	= 4.5;
	activityThresh		= 3.8;
}

//------------------------------
vector <card> cardFinder::findCardsFromBlobs(vector <ofxCvBlob> & possibleCards){
		vector <card> goodCards;
		goodCards.clear();
		
		int numBlobs = possibleCards.size();
		if(numBlobs <= 0){
			return goodCards;
		}
		
		//okay so the logic here is to find the cards based on contour
		//and the number of corners

		//at some point we want to cache the cards so that non moving cards
		//have steady corners
		
		for(int i = 0; i < numBlobs; i++){
			vector <ofxVec2f> smoothContour;
			contAna.smoothContour(possibleCards[i], smoothContour,  0.3);  
		
			//get the number of corners
			int numFound = corner.findCorners(smoothContour, cornerSensitivity);
			if( numFound != 4){
				continue;
			}
			
			goodCards.push_back(card());
			goodCards.back().setPoints(smoothContour[corner.getTipIndex(0)],  smoothContour[corner.getTipIndex(1)], smoothContour[corner.getTipIndex(2)], smoothContour[corner.getTipIndex(3)]);
			goodCards.back().center = possibleCards[i].centroid;
			cardGeom.calculateGeometry(goodCards.back());
		}
		
		return goodCards;
}
		