コード例 #1
0
 def _showBlobs( self, b ):
   img = self.raw.copy()
   if b is not None:
     for x,y in b:
       xy = (int(x),int(y))
       cv2_circle(img,xy,10,(0,255,0),thickness=2)
       #cv2_circle(img,xy,5,(0,0,0),thickness=-1)
   cv2_imshow('Tracker',img)
コード例 #2
0
 def play_image_sequence(self, frame_rate=25):
     """
     plot the images just like a video
     :return:
     """
     frame_duration = 1000 // frame_rate
     for i, img in enumerate(self.left_sequence):
         cv2_imshow('', img)
         cv2_waitKey(frame_duration)
         print('Frame-' + str(i + 1))
コード例 #3
0
 def run( self ):
   res,img = self.cam.read()
   if res:
       cv2_imshow('Tracker',img)
   try:
     while waitKey(5) not in {27,113}:
       self.work()
   finally:
     self.out.close()
     self.cam.release()
     destroyAllWindows()
     [ waitKey(50) for k in range(10) ]
     print "\n"+"*"*40+"\nSafely terminated\n"+"*"*40
コード例 #4
0
def pause(time, ground):
    while time >= 1:
        ground[np_shape(ground)[1] / 2 + 70:np_shape(ground)[1] / 2 + 100,
               np_shape(ground)[1] / 2 - 10:np_shape(ground)[1] / 2 +
               40, :] = 255
        cv2_putText(
            ground, str(time),
            (np_shape(ground)[1] / 2 - 5, np_shape(ground)[1] / 2 + 93),
            cv2_FONT_HERSHEY_SIMPLEX, 1, 0)
        cv2_imshow("Tic_Tac_Toe", ground)
        k = cv2_waitKey(1000) & 0xFF
        if k == 27:
            return 1
        elif k != 255:
            return 0
        time -= 1
    return 0
コード例 #5
0
    def __play_video(self, video_capture: VideoCapture, frame_rate: int,
                     title: str):
        frame_duration = 1000 // frame_rate
        # Frame counter
        i = 1

        while video_capture.isOpened():
            ret, frame = video_capture.read()
            if ret:
                # display frame
                cv2_imshow(title, frame)
                # wait 40ms and make another check before 'breaking'
                if cv2_waitKey(frame_duration) & 0xFF == ord('q'):
                    break
                i += 1
            else:
                break

        print('Video player:', i, 'consecutive frames were displayed.')
コード例 #6
0
 def work( self ):
   res,raw = self.cam.read()
   if not res:
       return
   self.raw = raw
   img = cvtColor(raw,COLOR_RGB2GRAY)
   self.img = img
   t = now()
   if self.bg is not None:
     d0 = img - (self.bg+3*self.bgs+self.guard)
     d1 = (d0 / max(64,d0.max())).clip(0,1)
     d2 = d1 * (img > 192)
     self.ind = 255-asarray(255*d2,uint8)
     cv2_imshow('ind',self.ind)
     kp = self.bd.detect(self.ind)
     b = [kpi.pt for kpi in kp]
     if self.out:
       self._outBlobs(t,b)
     self._showBlobs(b)
   if t-self.trr>self.rrRate:
     self._putRoundRobin( t, img )
     self.bg = mean( self.bgQ, axis=0 )
     self.bgs = std( self.bgQ, axis=0 )
コード例 #7
0
        # find the indexes of all matched faces then initialize a
        # dictionary to count the total number of times each face
        # was matched
        matchedIdxs = [i for (i, b) in enumerate(matches) if b]
        counts = {}

        # loop over the matched indexes and maintain a count for
        # each recognized face face
        for i in matchedIdxs:
            name = data["names"][i]
            counts[name] = counts.get(name, 0) + 1

        # determine the recognized face with the largest number of
        # votes (note: in the event of an unlikely tie Python will
        # select first entry in the dictionary)
        name = max(counts, key=counts.get)

    # update the list of names
    names.append(name)

# loop over the recognized faces
for ((top, right, bottom, left), name) in zip(boxes, names):
    # draw the predicted face name on the image
    cv2.rectangle(image, (left, top), (right, bottom), (0, 255, 0), 2)
    y = top - 15 if top - 15 > 15 else top + 15
    cv2.putText(image, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX, 0.75,
                (0, 255, 0), 2)

# show the output image
cv2.cv2_imshow(image)
cv2.waitKey(0)
コード例 #8
0
     cv2_putText(ground, "Hill", (30, 67), cv2_FONT_HERSHEY_SIMPLEX, 0.7,
                 [0, 0, 0], 2)
     cv2_circle(ground, (15, 90), 5, (190, 160, 80), 9)
     cv2_putText(ground, "Mountain", (30, 97), cv2_FONT_HERSHEY_SIMPLEX,
                 0.7, [0, 0, 0], 2)
     cv2_circle(ground, (15, 120), 5, (20, 110, 180), 9)
     cv2_putText(ground, "Forrest", (30, 127), cv2_FONT_HERSHEY_SIMPLEX,
                 0.7, [0, 0, 0], 2)
     cv2_circle(ground, (15, 150), 5, (50, 250, 240), 9)
     cv2_putText(ground, "Field", (30, 157), cv2_FONT_HERSHEY_SIMPLEX, 0.7,
                 [0, 0, 0], 2)
     cv2_circle(ground, (15, 180), 5, (80, 255, 80), 9)
     cv2_putText(ground, "Pasture", (30, 187), cv2_FONT_HERSHEY_SIMPLEX,
                 0.7, [0, 0, 0], 2)
 if name % 100 == 0:
     cv2_imshow('CATAN', ground)
 if name % 100000 == 1:
     d_sub = D_main + "\\" + str(
         (name / 100000) * 100) + str(n_k) + '-' + str(
             (1 + name / 100000) * 100) + 'K'
     #folder(d_sub)
 if name % 10000 == 1:
     d_sub_1 = d_sub + "\\" + str(
         (name / 10000) * 10) + str(n_k) + '-' + str(
             (1 + name / 10000) * 10) + 'K'
     #folder(d_sub_1)
 if name % 1000 == 1:
     d_sub_2 = d_sub_1 + "\\" + str(
         name / 1000) + str(n_k) + '-' + str(1 + name / 1000) + 'K' + direct
     n_k = "K"
     folder(d_sub_2)
コード例 #9
0
turn = 0
while True:
    player_1 = []
    player_2 = []
    ground = np_ones((dim_y, dim_x, 3)) * 255
    ground = ground.astype('uint8')

    out_lines = lines(ground, dim_x, dim_y)
    out_points = center_points(out_lines)

    for i in xrange(9):
        cv2_putText(ground, str(i + 1),
                    (out_points[i, 1] - 5, out_points[i, 0]),
                    cv2_FONT_HERSHEY_SIMPLEX, 1, 0)
    while True:
        cv2_imshow("Tic_Tac_Toe", ground)
        key = cv2_waitKey(1) & 0xFF
        if key == 27:
            brk = 1
            break
        elif key != 255:
            if key == 9:
                cv2_imwrite('tic_tac_toe.PNG', ground)
            if 49 <= key <= 57:
                turn = fill_pose(ground, out_points, key, turn)
                #cv2_imshow("Tic_Tac_Toe",ground)
                br = winner(ground, turn, key, player_1, player_2)
                cv2_imshow("Tic_Tac_Toe", ground)
                if br == 1 or br == 2:
                    pl1 += (br == 1) * 1
                    pl2 += (br == 2) * 1