def test(): #start = time.time() # src1 = cv.LoadImage("target_all_nl1.png", 0) src2 = cv.LoadImage("target_all.png", 0) # crop area pt1 = (100, 100) pt2 = (200, 200) #get img size and compare # convert cvMat to IplImage crop1 = cv.GetImage(src1[pt1[1]:pt2[1], pt1[0]:pt2[0]]) crop2 = cv.GetImage(src2[pt1[1]:pt2[1], pt1[0]:pt2[0]]) # save image cv.SaveImage("c1.jpg", crop1) cv.SaveImage("c2.jpg", crop2) print type(crop2) print type(src2) #cv2.GetMat # compute hist1 = compute_histogram(crop1) hist2 = compute_histogram(crop2) # compare sc = cv.CompareHist(hist1, hist2, cv.CV_COMP_CHISQR) print sc
def test(): #start = time.time() # src1 = cv.LoadImage("all.png", 0) src2 = cv.LoadImage("dark3.png", 0) # crop area w = 100 pt1 = (535, 60) pt2 = (pt1[0] + w, pt1[1] + w) print pt1 print pt2 #get img size and compare # convert cvMat to IplImage crop1 = src1[pt1[1]:pt2[1], pt1[0]:pt2[0]] crop2 = src2[pt1[1]:pt2[1], pt1[0]:pt2[0]] crop3 = cv.GetImage(cv.GetSubRect(src1, (10, 10, 100, 100))) crop4 = cv.GetImage(cv.GetSubRect(src2, (10, 10, 100, 100))) # save image cv.SaveImage("c01.jpg", crop1) cv.SaveImage("c02.jpg", crop2) cv.SaveImage("c03.jpg", crop3) cv.SaveImage("c04.jpg", crop4) print type(src1) print type(crop3) #cv2.GetMat # compute #return 1 hist1 = compute_histogram(crop3) hist2 = compute_histogram(crop4) # compare sc = cv.CompareHist(hist1, hist2, cv.CV_COMP_CHISQR) print sc
def test(): #start = time.time() src1 = cv.GetMat(cv.LoadImage("d1.png", 0)) src2 = cv.GetMat(cv.LoadImage("d2.png", 0)) pt1 = (100, 100) pt2 = (200, 200) crop1 = src1[pt1[1]:pt2[1], pt1[0]:pt2[0]] crop2 = src2[pt1[1]:pt2[1], pt1[0]:pt2[0]] #cv2.GetMat hist1 = compute_histogram(crop1) hist2 = compute_histogram(crop2) sc = cv.CompareHist(hist1, hist2, cv.CV_COMP_CHISQR) print sc
def imgcompare(image1, image2): img1 = cv.LoadImage(image1) hist1 = createHist(img1) img2 = cv.LoadImage(image2) hist2 = createHist(img2) return cv.CompareHist(hist1, hist2, cv.CV_COMP_CORREL)
def compare_ref(self, polygon): '''Compare new polygon against the reference polygon histogram''' (image, mask) = self.get_working() return cv.CompareHist(self.ref_hist, hs_histogram(image, mask), cv.CV_COMP_CORREL)