예제 #1
0
파일: main.py 프로젝트: cjcjcj/mt_n16
def video_mode():
   timer=default_timer
   space_stopped=False

   img = cv2.imread('123.jpg')
   params = {'original_image' : img.copy(), 'marked_image' : img.copy(),
             'winName' : 'image'}
   del img

   start, stop = time_gen(timer)
   drawer.callbacks = {'start':start, 'stop':stop}
   drawer.params = params

   cv2.namedWindow(params['winName'])
   cv2.setMouseCallback(params['winName'], drawer.cb_f, param=params)

   cap = cv2.VideoCapture('1.mp4')
   fn = -1
   points = dict()
   while True:
      if not timer['wait']:
         fn += 1
         if drawer.points:
            points[fn] = drawer.points[:]
         ret, frame = cap.read()
         if not ret: break
         update_images(params, frame)
         drawer.redraw_marked()

      k = cv2.waitKey(timer['delay']) & 0xFF
      # print(k,timer['wait'])
      if k in quit_codes:
         break
      elif k == keys_codes['F5']:
         drawer.redraw_marked()
      elif k == keys_codes['-']:
         drawer.delete_rect()
      elif k == keys_codes[' ']:
         timer['delay']=33 if space_stopped else 0
         space_stopped=False if space_stopped else True
      elif k in keys_to_classes:
         drawer.update_cur_class(keys_to_classes[k])
   
   cv2.destroyAllWindows()
   
   if points:
      points_to_xml(points.values()[0], skipped = False)
예제 #2
0
파일: main.py 프로젝트: cjcjcj/mt_n16
def frames_mode(srcdir, tdir):
   flist = [
      os.path.join(srcdir,f) for f in os.listdir(srcdir)
                             if f.lower().endswith('png')
   ]
   flist.sort()
   params = {'container' : None, 'winName' : 'image'}
   flist = DLL(flist)
   process_result = get_result_processing_funcion(tdir)
  
   cv2.namedWindow(params['winName'])
   cv2.setMouseCallback(params['winName'], drawer.cb_f, param=params)
   
   timer = {'delay' : 1, 'wait' : False}
   # start, stop = time_gen(timer)
   # drawer.callbacks['stop'] = stop
   # drawer.callbacks['start'] = start
   drawer.params = params
   process_result(flist.next, params)

   k = -1
   skipped=False
   tp,fp,fn = (0,)*3
   try:
      while k not in quit_codes and not flist.is_ended():
         if k == keys_codes[' ']:
            process_result(flist.next, params, skipped)
            skipped = False
            print('{} {} {}'.format(tp,fp,fn))
         elif k == keys_codes['lctrl']:
            process_result(flist.prev, params, skipped)
            skipped = False
         elif k == keys_codes['-']:
            drawer.delete_rect()
         elif k == keys_codes['s']:
            skipped = not skipped
         elif k in keys_to_classes:
            drawer.update_cur_class(keys_to_classes[k])

         elif k == keys_codes['z']:
            tp+=1
         elif k == keys_codes['Z']:
            tp-=1

         elif k == keys_codes['x']:
            fp+=1
         elif k == keys_codes['X']:
            fp-=1

         elif k == keys_codes['c']:
            fn+=1
         elif k == keys_codes['C']:
            fn-=1

         k = cv2.waitKey(timer['delay']) & 0xFF
         # print(params['container'].points)

         # if not timer['wait']:
         # print(params['container'].active_img is params['container'].image.img)
         cv2.imshow(params['winName'], params['container'].active_img)
   except:
      pass
   
   cv2.destroyAllWindows()

   print('{}\n\ttp: {}\n\tfp: {}\n\tfn: {}'.format(os.path.basename(srcdir), tp, fp, fn))
   print('|{}|{}|{}|{}|'.format(os.path.basename(srcdir), tp, fp, fn))