def validate_corners(self, new_corners): L = len(new_corners) not_valid = [0] * L for i, cor1 in enumerate(new_corners): cor2 = new_corners[(i + 1) % L] if cor1 is None or cor2 is None: continue v1p, v1n = cor1.vp, cor1.vn v2p, v2n = cor2.vp, cor2.vn v12 = vector(cor1.p, cor2.p) v21 = vector(cor2.p, cor1.p) v12a = vectorAngle(v1p, v12) v21a = vectorAngle(v2n, v21) min1a, max1a = get_angle_range(v1p, v1n, 1) min2a, max2a = get_angle_range(v2n, v2p, 1) if not (min1a < v12a < max1a) or not (min2a < v21a < max2a): if cor1.similarity < cor2.similarity: not_valid[(i + 1) % L] += 1 else: not_valid[i] += 1 for i in range(L): if not_valid[i] > 0: db.pr(["corner ", new_corners[i], "not_valid with score", not_valid[i]], "validate_corners") new_corners[i] = None db.pr(not_valid, "validate_corners") pass
def run_tests(num_tests_0=100, num_tests_1=100,dataset='yoho'): if dataset is 'yoho': pr('Testing with YOHO dataset with ' + str(num_tests_0) + 'class 0 tests and ' + str(num_tests_1) + ' class 1 tests' + 'with files at' + YOHO_PATH) users_paths = os.listdir(test_path) return NUM_TESTS, assignments, y_score elif dataset is 'timit': pass elif dataset is 'nist': pass pass
def main(): if CAM == 0: provider = MovieImageProvider('../resources/Video5.avi', 0, 0) else: provider = CamImageProvider(0, '../resources/Video5.avi') db.start_at(provider, 110) img, imgtime = provider.update_image() print(img, imgtime, time.time()) db.pr([img]) sd = SquareDetector(img) # ,imgtime,1, False ) for i in [0, 30]: sd.add_marker(Square(i)) # win='Result' # canny='Canny' # tmp='Temp' # cv.NamedWindow(win) # cv.NamedWindow(tmp) # cv.MoveWindow(win,0,0) # cv.MoveWindow(tmp,650,0) ti = 0.01 while True: k = cv.WaitKey(1) if k == 27: break elif k == 2424832: step = -1 elif k == 32: cv.WaitKey(delay=0) step = 1 else: step = 1 start = time.time() img, imgtime = provider.update_image() if img is None: break if provider.index == 112: pass sq = sd.find_markers(img, imgtime) sd.draw_markers(img) sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15), (0, 0, 0)) cv.ShowImage('test', sd.draw_img) db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10) ti = time.time() - start cv.WaitKey(1)
def find_corners(self): ''' Tries to find corners or to predict them. Return empty list, if every corner is found, or list of points in the area which tell where to do futher checking ''' time = self.m_d.time if time-self.last_seen >= MAX_SEEN: return False #cv.ResetImageROI(draw_img) ncorners = [] bounds = [] for c in self.corners: db.db_break("find_corners") cands = c.get_candidates(self.m_d) min = NOT_SIMILLAR; bestcand = None; for cand in cands: if cand.similarity < min: min = cand.similarity; bestcand = cand ncorners.append(bestcand) bounds.extend(cvrect(cv.GetImageROI(self.m_d.bw_img))) if bestcand is None: pass db.pr([ncorners], "find_corners") for cor in ncorners: if cor is not None: cor.draw(self.m_d.tmp_img) if None in ncorners: pass CP = CornerPredictor(self.corners, time, self.m_d) ncorners = CP.predict_corners(ncorners) db.pr([ncorners], "new corners") if ncorners is not None: points = [x.p for x in ncorners] correctness = self.code_correctness(points) if correctness>REQUIRED_CORRECTNESS: self.set_new_position(ncorners) return True else: db.PolyLine(self.m_d.tmp_img,[points], True, (255,255,255), "%.2f"%correctness) self.m_d.borders.extend(CP.bounds) return False
def find_corners(self): ''' Tries to find corners or to predict them. Return empty list, if every corner is found, or list of points in the area which tell where to do futher checking ''' time = self.m_d.time if time - self.last_seen >= MAX_SEEN: return False #cv.ResetImageROI(draw_img) ncorners = [] bounds = [] for c in self.corners: db.db_break("find_corners") cands = c.get_candidates(self.m_d) min = NOT_SIMILLAR bestcand = None for cand in cands: if cand.similarity < min: min = cand.similarity bestcand = cand ncorners.append(bestcand) bounds.extend(cvrect(cv.GetImageROI(self.m_d.bw_img))) if bestcand is None: pass db.pr([ncorners], "find_corners") for cor in ncorners: if cor is not None: cor.draw(self.m_d.tmp_img) if None in ncorners: pass CP = CornerPredictor(self.corners, time, self.m_d) ncorners = CP.predict_corners(ncorners) db.pr([ncorners], "new corners") if ncorners is not None: points = [x.p for x in ncorners] correctness = self.code_correctness(points) if correctness > REQUIRED_CORRECTNESS: self.set_new_position(ncorners) return True else: db.PolyLine(self.m_d.tmp_img, [points], True, (255, 255, 255), "%.2f" % correctness) self.m_d.borders.extend(CP.bounds) return False
def main(): if CAM == 0: provider = MovieImageProvider('../resources/Video5.avi', 0, 0) else: provider = CamImageProvider(0, '../resources/Video5.avi') db.start_at(provider, 110) img, imgtime = provider.update_image() print(img, imgtime, time.time()) db.pr([img]); sd = SquareDetector(img) # ,imgtime,1, False ) for i in [0, 30]: sd.add_marker(Square(i)) # win='Result' # canny='Canny' # tmp='Temp' # cv.NamedWindow(win) # cv.NamedWindow(tmp) # cv.MoveWindow(win,0,0) # cv.MoveWindow(tmp,650,0) ti = 0.01 while True: k = cv.WaitKey(1) if k == 27: break elif k == 2424832: step = -1 elif k == 32: cv.WaitKey(delay=0) step = 1 else: step = 1; start = time.time() img, imgtime = provider.update_image() if img == None: break; if provider.index == 112: pass sq = sd.find_markers(img, imgtime) sd.draw_markers(img) sd.putText("Frame: %d %.3f FPS" % (provider.index, (1 / ti)), (0, 15), (0, 0, 0)) cv.ShowImage('test', sd.draw_img) db.show([img, sd.draw_img, sd.bw_img], 'main', 0, 10) ti = time.time() - start cv.WaitKey(1)