コード例 #1
0
def show_recognize(clf, img, rects):
    red = [0,0,0xff]
    if len(rects) == 0:
        return 

    for i,rect in enumerate(rects):
        img2 = op.get_subimage(img, rect[0], rect[1])
        cv2.imshow(str(i),img2)
        res = model.recognize_number(clf, img2)

        cv2.putText(img, str(int(res)), rect[0], cv2.FONT_HERSHEY_SIMPLEX,0.8, red, thickness = 2)
コード例 #2
0
def show_recognize(clf, img, rects):
    red = [0, 0, 0xff]
    if len(rects) == 0:
        return

    for i, rect in enumerate(rects):
        img2 = op.get_subimage(img, rect[0], rect[1])
        cv2.imshow(str(i), img2)
        res = model.recognize_number(clf, img2)

        cv2.putText(img,
                    str(int(res)),
                    rect[0],
                    cv2.FONT_HERSHEY_SIMPLEX,
                    0.8,
                    red,
                    thickness=2)
コード例 #3
0
def get_score_info(video):
    global step
    score_frames = []
    twenty_four_frames = []
    camera_change_frames = []

    score_a, score_b = 0, 0  # score of both team
    last_sec = 0  # 24 second board
    #    last_frame = None
    pos = 0  # frame position
    video.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos)
    clf = model.load_classifier()
    while (video.isOpened()):
        if pos % step == 0:
            ret, frame = video.red()
        else:
            ret = video.grab()

        if not ret:
            break

        # skip each step steps
        if pos % step != 0:
            pos += 1
            continue

        # if camera change
        if pos != 0 and hist.camera_change(last_frame, frame):
            camera_change_frames.append(pos)
            print 'camera change', pos
        last_frame = frame

        if op.has_score_board(frame, target_imgs[0], rects[0]):
            # score a
            img = op.get_subimage(frame, rects[1][0], rects[1][1])
            num = model.recognize_number(clf, img)
            #            print 'a ', num
            if score_two_or_three(num, score_a):
                score_frames.append(pos)
                print 'a from', score_a, 'to', num, pos
            if not noise(num, score_a):
                score_a = num

            # score b
            img = op.get_subimage(frame, rects[2][0], rects[2][1])
            num = model.recognize_number(clf, img)
            #            print 'b ', num
            if score_two_or_three(num, score_b):
                score_frames.append(pos)
                print 'b from', score_b, 'to', num, pos
            if not noise(num, score_b):
                score_b = num

            # 24 second board
            img = op.get_subimage(frame, rects[3][0], rects[3][1])
            sec = model.recognize_number(clf, img)
            if last_sec != 24 and sec == 24:
                print 'twenty four', pos
                twenty_four_frames.append(pos)
            last_sec = sec

        pos += 1


#        print pos

    print score_frames, twenty_four_frames, camera_change_frames
    return score_frames, twenty_four_frames, camera_change_frames
コード例 #4
0
def get_score_info(video):
    global step
    score_frames = []
    twenty_four_frames = []
    camera_change_frames = []

    score_a, score_b = 0,0 # score of both team
    last_sec = 0 # 24 second board 
#    last_frame = None
    pos = 0 # frame position
    video.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos)
    clf = model.load_classifier()
    while(video.isOpened()):
        if pos % step == 0: 
            ret, frame = video.red()
        else:
            ret = video.grab()
        
        if not ret:
            break
        
        # skip each step steps
        if pos % step != 0: 
            pos += 1
            continue

        # if camera change
        if pos != 0 and hist.camera_change(last_frame, frame):
            camera_change_frames.append(pos)
            print 'camera change', pos
        last_frame = frame 


        if op.has_score_board(frame, target_imgs[0], rects[0]):
            # score a
            img = op.get_subimage(frame, rects[1][0], rects[1][1])
            num = model.recognize_number(clf, img)
#            print 'a ', num
            if score_two_or_three(num,score_a):
                score_frames.append(pos)
                print 'a from',score_a,'to',num, pos
            if not noise(num, score_a):
                score_a = num

            # score b
            img = op.get_subimage(frame, rects[2][0], rects[2][1])
            num = model.recognize_number(clf, img)
#            print 'b ', num
            if score_two_or_three(num,score_b):
                score_frames.append(pos)
                print 'b from',score_b,'to', num, pos
            if not noise(num, score_b):
                score_b = num

            # 24 second board
            img = op.get_subimage(frame, rects[3][0], rects[3][1])
            sec = model.recognize_number(clf, img)
            if last_sec != 24 and sec == 24:
                print 'twenty four',pos
                twenty_four_frames.append(pos) 
            last_sec = sec

        pos += 1 
#        print pos

    print score_frames, twenty_four_frames, camera_change_frames
    return score_frames,twenty_four_frames,camera_change_frames