def get_haar_roi_points(self, haarCascade, rect, origSize=(0, 0), method=1): """ Search for points matching the haarcascade selected. Arguments: - self: The main object pointer. - haarCascade: The selected cascade. - methode: The search method to use. DEFAULT: co.cv.CV_HAAR_DO_CANNY_PRUNING. Returns a list with the matches. """ cascade = cv2.CascadeClassifier(haarCascade) if not cascade: debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" ) #FIXME: Work around to fix when the rect is too big if (rect[0]+rect[2]) > self.img.width: rect = (rect[0], rect[1], self.img.width-rect[0],self.img.height-rect[1]) if (rect[1]+rect[3]) > self.img.height: rect = (rect[0], rect[1], self.img.width-rect[0],self.img.height-rect[1]) imageROI = self.img[rect[1]:rect[3], rect[0]:rect[2]] if cascade: points = cascade.detectMultiScale(imageROI,1.2,2,method,(20,20)) else: debug.exception( "ocvfw", "The Haar Classifier Cascade load Failed (ROI)" ) if points: matches = [ [ ( int(r[0][0]*origSize[0]), int(r[0][1]*origSize[1])), \ ( int((r[0][0]+r[0][3])+origSize[0]), int((r[0][1]+r[0][2])*origSize[1]) )] \ for r in points] debug.debug( "ocvfw", "cmGetHaarROIPoints: detected some matches" ) return matches
def get_haar_points(self, haarCascade, method=1): """ Search for points matching the haarcascade selected. Arguments: - self: The main object pointer. - haarCascade: The selected cascade. - methode: The search method to use. DEFAULT: co.cv.CV_HAAR_DO_CANNY_PRUNING. Returns a list with the matches. """ cascade = cv2.CascadeClassifier(haarCascade) if not cascade: debug.exception( "ocvfw", "The Haar Classifier Cascade load failed" ) self.small_img = cv2.resize(self.img,(self.small_img.shape[0],self.small_img.shape[1]),self.small_img,0,0,cv2.INTER_LINEAR) points = cascade.detectMultiScale(self.small_img,1.2,2,method,(20,20)) if numpy.any(points): matches = [ [ ( int(r[0]*self.imageScale), int(r[1]*self.imageScale)), \ ( int((r[0]+r[3])*self.imageScale), int((r[0]+r[2])*self.imageScale) )] \ for r in points] debug.debug( "ocvfw", "cmGetHaarPoints: detected some matches" ) return matches