コード例 #1
0
def main():
    thresholdValue = [108]
    chooseInt = [0]

    # Size of trackbars
    trackbar_width = 400

    #init cvui
    cvui.init(WINDOW_NAME, 20)
    ui_frame = np.zeros((480, 640, 3), np.uint8)

    #camera setting
    cap = cv2.VideoCapture(0)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480)

    #main loop
    while (True):
        ret, frame = cap.read()

        #print frame.dtype
        #to gray
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        ui_frame[:] = (49, 52, 49)
        cvui.beginColumn(ui_frame, 20, 20, -1, -1, 6)

        cvui.text('Threshold Adject')
        cvui.trackbar(trackbar_width, thresholdValue, 0, 255)

        cvui.counter(chooseInt)

        cvui.space(5)

        cvui.text(strArr[chooseInt[0]])

        if cvui.button('&Quit'):
            break

        cvui.space(5)

        cvui.endColumn()

        th1, gray = cv2.threshold(gray, thresholdValue[0], 255,
                                  chooseArr[chooseInt[0]])
        merged = cv2.merge([gray, gray, gray])

        dst = cv2.addWeighted(ui_frame, 1.0, merged, 0.4, 0.0)

        cvui.update()

        cv2.imshow(WINDOW_NAME, dst)

    cap.release()
    cv2.destroyAllWindows()
コード例 #2
0
def printStuffOnCtrlImg(frameCtrl, frameNum, x, y, l, minn, maxx, name, hint):
  cvui.text(frameCtrl, x, y, name)
  
  status = cvui.iarea(x, y, 350, 60)
  if status == cvui.OVER:
    cvui.text(frameCtrl, 4, 15, hint)
    
  if name != "Frame number":
    if (frameNum[0] - minn) > (maxx - minn) * 0.9:
      maxx = minn + (frameNum[0] - minn) * 1.25
    if maxx - minn > 255:
      if frameNum[0] < minn + (maxx - minn) * 0.1:
        maxx = minn + (maxx - minn) * 0.9

  cvui.trackbar(frameCtrl, x,      y+10, l, frameNum, minn, maxx)
  cvui.counter(frameCtrl,  x+l+10, y+20,    frameNum)
  
  return [minn, maxx]
コード例 #3
0
 def update_cvui(self):
     if self.cvui_frame is None:
         return
     self.cvui_frame[:] = (49, 52, 49)
     if True:
         cvui.text(self.cvui_frame, 20, 30, 'DBSCAN')
         cvui.text(self.cvui_frame, 40, 60, 'eps')
         cvui.counter(self.cvui_frame, 110, 55, self.cvui_dbscan_eps, 0.001,
                      '%.3f')
         cvui.text(self.cvui_frame, 40, 90, 'minpoints')
         cvui.counter(self.cvui_frame, 110, 85, self.cvui_dbscan_minpoints,
                      1, '%d')
     cvui.imshow(CVUI_WINDOW_NAME, self.cvui_frame)
     cv_key = cv2.waitKey(1)
     if cv_key == 27:
         self.call_exit()
     elif cv_key == 110:
         self.call_next()
     elif cv_key == 98:
         self.call_prev()
     elif cv_key == 114:
         self.call_refit()
     elif cv_key == 113:
         self.call_exit()
     elif cv_key == 118:
         self.call_default_view()
     elif cv_key == 102:
         self.call_toggle_fitgeom()
     elif cv_key == 50:
         self.call_toggle_2d()
     elif cv_key == 51:
         self.call_toggle_3d()
     elif cv_key == 99:
         self.call_toggle_targetcolor()
     elif cv_key == 100:
         self.call_toggle_apply_fit()
     elif cv_key == 97:
         self.call_toggle_auto_mode()
     elif cv_key != -1:
         print(cv_key)
コード例 #4
0
def prepareConfigFileForParamsAdjustements(configFile, wellNumber, firstFrameParamAdjust, videoToCreateConfigFileFor, adjustOnWholeVideo):
  
  initialFirstFrameValue = -1
  initialLastFrameValue  = -1
  if "firstFrame" in configFile:
    initialFirstFrameValue = configFile["firstFrame"]
  if "lastFrame" in configFile:
    initialLastFrameValue  = configFile["lastFrame"]
  
  cap = cv2.VideoCapture(videoToCreateConfigFileFor)
  max_l = int(cap.get(7))
  if int(firstFrameParamAdjust):
    cap.set(1, 1)
    ret, frame = cap.read()
    WINDOW_NAME = "Choose where you want to start the procedure to adjust parameters."
    WINDOW_NAME_CTRL = "Control"
    cvui.init(WINDOW_NAME)
    cv2.moveWindow(WINDOW_NAME, 0,0)
    cvui.init(WINDOW_NAME_CTRL)
    cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
    value = [1]
    curValue = value[0]
    buttonclicked = False
    widgetX = 40
    widgetY = 50
    widgetL = 300
    while not(buttonclicked):
      value[0] = int(value[0])
      if curValue != value[0]:
        cap.set(1, value[0])
        frameOld = frame
        ret, frame = cap.read()
        if not(ret):
          frame = frameOld
        curValue = value[0]
      frameCtrl = np.full((200, 400), 100).astype('uint8')
      frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0
      cvui.text(frameCtrl, widgetX, widgetY, 'Frame')
      cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, 0, max_l-1)
      cvui.counter(frameCtrl, widgetX, widgetY+60, value)
      buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the procedure to start at this frame.")
      cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward')
      cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward')
      cvui.imshow(WINDOW_NAME, frame)
      cvui.imshow(WINDOW_NAME_CTRL, frameCtrl)
      r = cv2.waitKey(20)
      if (r == 54) or (r == 100) or (r == 0):
        value[0] = value[0] + 1
      elif (r == 52) or (r == 97) or (r == 113):
        value[0] = value[0] - 1
      elif (r == 103):
        value[0] = value[0] - 30
      elif (r == 104):
        value[0] = value[0] + 30
      elif (r == 102):
        value[0] = value[0] - 100
      elif (r == 106):
        value[0] = value[0] + 100
    configFile["firstFrame"] = int(value[0])
    cv2.destroyAllWindows()
    if not(int(adjustOnWholeVideo)):
      if ("lastFrame" in configFile):
        if (configFile["lastFrame"] - configFile["firstFrame"] > 500):
          configFile["lastFrame"] = configFile["firstFrame"] + 500
      else:
        configFile["lastFrame"]  = min(configFile["firstFrame"] + 500, max_l-10)
  else:
    if not(int(adjustOnWholeVideo)):
      if ("firstFrame" in configFile) and ("lastFrame" in configFile):
        if configFile["lastFrame"] - configFile["firstFrame"] > 500:
          configFile["lastFrame"] = configFile["firstFrame"] + 500
      else:
        configFile["firstFrame"] = 1
        configFile["lastFrame"]  = min(max_l-10, 500)
  
  if "lastFrame" in configFile:
    if configFile["lastFrame"] > initialLastFrameValue and initialLastFrameValue != -1:
      configFile["lastFrame"] = initialLastFrameValue
  
  if len(wellNumber) != 0:
    configFile["onlyTrackThisOneWell"] = int(wellNumber)
  else:
    configFile["onlyTrackThisOneWell"] = 0
  
  configFile["reloadBackground"] = 1
  
  return [configFile, initialFirstFrameValue, initialLastFrameValue]
コード例 #5
0
    def onWork(self):
        self.frame[:] = (49, 52, 49)
        char = cv.waitKey(1)

        doOverw = False

        writeOnName = False
        writeOnSubject = False
        writeOnProf = False

        stringCopy = ''
        stringCopyColor = 0x10dca1

        while True:

            cursor = cvui.mouse(WINDOW_NAME)
            click = cvui.mouse(cvui.CLICK)

            # (self, x, y, w, h, title, char, writeOn, cursor, click, writeOnBool):
            writeOnName, self.folderName = self.textInput(
                5, 5, 305, 40, "Folder Name:", char, self.folderName, cursor,
                click, writeOnName)

            writeOnSubject, self.subjectName = self.textInput(
                5 + X_SCREEN / 2, 5, 305, 40, "Subject Name:", char,
                self.subjectName, cursor, click, writeOnSubject)

            writeOnProf, self.tempName = self.textInput(
                5 + X_SCREEN / 2, 105, 305, 40, "Professors:", char,
                self.tempName, cursor, click, writeOnProf)
            cvui.rect(self.frame, 6 + X_SCREEN / 2, 155, X_SCREEN / 2 - 63,
                      235 - 165, 0x8d9797, 0x3c4747)
            cvui.rect(self.frame, X_SCREEN - 52, 155, 47, 235 - 165, 0x8d9797,
                      0x293939)
            if cvui.button(
                    self.frame, X_SCREEN - 49, 157,
                    "+") and not self.tempName == '' and len(self.names) < 4:
                self.names.append(self.tempName)
                self.tempName = ''
            if cvui.button(self.frame, X_SCREEN - 49, 196,
                           "-") and not len(self.names) == 0:
                del self.names[-1]

            for i in range(len(self.names)):
                cvui.printf(self.frame, 10 + X_SCREEN / 2, 160 + 15 * i, 0.4,
                            0xdd97fb, self.names[i])

            xp = int((X_SCREEN - 20) / 4)

            cvui.window(self.frame, 5, 235, X_SCREEN - 10, Y_SCREEN - 235 - 5,
                        "Premade:")
            if cvui.button(self.frame, 10 + xp - 10 * 11, 260, "Lab. Micro."):
                self.subjectName = '22.99 Laboratorio De Microprocesadores'
                self.names.clear()
                self.names.append('Jacoby, Daniel Andres')
                self.names.append('Magliola, Nicolas')
                self.names.append('Ismirlian, Diego Matias')
                self.group[0] = 3

            if cvui.button(self.frame, 10 + xp * 2 - 10 * 7, 260, "Control"):
                self.subjectName = '22.85 Sistemas de Control'
                self.names.clear()
                self.names.append('Nasini, Victor Gustavo')
                self.names.append('Zujew, Cristian Alejo')

            if cvui.button(self.frame, 10 + xp * 3 - 10 * 9, 260, "Transinfo"):
                self.subjectName = '22.61 Transmision de la Informacion'
                self.names.clear()
                self.names.append('Bertucci, Eduardo Adolfo')
                self.names.append('Vila Krause, Luis Gustavo')

            if cvui.button(self.frame, 10 + xp * 4 - 10 * 11, 260,
                           "Electromag."):
                self.subjectName = '22.37 Electromagnetismo'
                self.names.clear()
                self.names.append('Munoz, Claudio Marcelo')
                self.names.append('Dobrusin, Pablo')

            cvui.printf(self.frame, 5, 55, 0.4, 0xdd97fb, f'N Exercises:')
            cvui.counter(self.frame, 5, 70, self.numberFolder)
            if self.numberFolder[0] <= 0:
                cvui.rect(self.frame, 5 + 25, 72, 40, 17, 0x292929, 0x292929)
                self.numberFolder[0] = 1
                cvui.printf(self.frame, 5 + 41, 76, 0.4, 0x9C9C9C, '1')

            cvui.printf(self.frame, 5 + X_SCREEN / 6, 55, 0.4, 0xdd97fb,
                        f'Day:')
            cvui.counter(self.frame, 5 + X_SCREEN / 6, 70, self.day)
            if self.day[0] <= 0:
                cvui.rect(self.frame, 5 + X_SCREEN / 6 + 25, 72, 40, 17,
                          0x292929, 0x292929)
                self.day[0] = 1
                cvui.printf(self.frame, 5 + X_SCREEN / 6 + 41, 76, 0.4,
                            0x9C9C9C, '1')
            elif self.day[0] >= 31:
                self.day[0] = 31

            cvui.printf(self.frame, 5 + X_SCREEN * 2 / 6, 55, 0.4, 0xdd97fb,
                        f'Month:')
            cvui.counter(self.frame, 5 + X_SCREEN * 2 / 6, 70, self.month)
            if self.month[0] <= 0:
                cvui.rect(self.frame, 5 + X_SCREEN * 2 / 6 + 25, 72, 40, 17,
                          0x292929, 0x292929)
                self.month[0] = 1
                cvui.printf(self.frame, 5 + X_SCREEN * 2 / 6 + 41, 76, 0.4,
                            0x9C9C9C, '1')
            elif self.month[0] >= 12:
                self.month[0] = 12

            cvui.printf(self.frame, 5 + X_SCREEN * 3 / 6, 55, 0.4, 0xdd97fb,
                        f'Year:')
            cvui.counter(self.frame, 5 + X_SCREEN * 3 / 6, 70, self.year)
            if self.year[0] <= 19:
                cvui.rect(self.frame, 5 + X_SCREEN * 3 / 6 + 25, 72, 40, 17,
                          0x292929, 0x292929)
                self.year[0] = 20
                cvui.printf(self.frame, 5 + X_SCREEN * 3 / 6 + 37, 76, 0.4,
                            0x9C9C9C, '20')
            elif self.year[0] >= 22:
                self.year[0] = 22

            cvui.printf(self.frame, 5 + X_SCREEN * 4 / 6, 55, 0.4, 0xdd97fb,
                        f'N Group:')
            cvui.counter(self.frame, 5 + X_SCREEN * 4 / 6, 70, self.group)
            if self.group[0] <= 0:
                cvui.rect(self.frame, 5 + X_SCREEN * 4 / 6 + 25, 72, 40, 17,
                          0x292929, 0x292929)
                self.group[0] = 1
                cvui.printf(self.frame, 5 + X_SCREEN * 4 / 6 + 41, 76, 0.4,
                            0x9C9C9C, '1')
            elif self.group[0] >= 7:
                self.group[0] = 7

            cvui.printf(self.frame, 5 + X_SCREEN * 5 / 6, 55, 0.4, 0xdd97fb,
                        f'N TP:')
            cvui.counter(self.frame, 5 + X_SCREEN * 5 / 6, 70, self.tp)
            if self.tp[0] <= 0:
                cvui.rect(self.frame, 5 + X_SCREEN * 5 / 6 + 25, 72, 40, 17,
                          0x292929, 0x292929)
                self.tp[0] = 1
                cvui.printf(self.frame, 5 + X_SCREEN * 5 / 6 + 41, 76, 0.4,
                            0x9C9C9C, '1')

            if cvui.button(self.frame, X_SCREEN / 4 - 10 * 16 / 2, 110,
                           "Load Folder Path") and not doOverw:
                self.folderPath = self.getPath()

            cvui.window(self.frame, 5, 155, X_SCREEN / 2 - 10, 40,
                        "Folder Path Selected")
            if len(self.folderPath) < MAXCHAR + 3:
                cvui.printf(self.frame, 10, 180, 0.4, 0xdd97fb,
                            self.folderPath)
            else:
                cvui.printf(self.frame, 10, 180, 0.4, 0xdd97fb,
                            self.folderPath[0:MAXCHAR + 2] + '...')

            if (not self.folderPath
                    == '') and (not self.folderName
                                == '') and (not self.subjectName == ''):
                if cvui.button(self.frame, 120, 200, "Start Copy"):
                    self.startCopy = True
                    stringCopy = "Wait While Copying..."
                    stringCopyColor = 0xdc1076

            cvui.printf(self.frame, 5, 205, 0.4, stringCopyColor, stringCopy)

            if self.startCopy:
                self.startCopy = False

                while self.folderName[-1] == ' ':  #32:
                    self.folderName = self.folderName[:-1]

                finalPath = self.folderPath + '/' + self.folderName

                coping = self.copyFolders(self.numberFolder[0], finalPath,
                                          True)

                if not coping == None:
                    if not coping:
                        doOverw = True
                    else:
                        stringCopy = "Copy Done!"
                        stringCopyColor = 0x10dca1
                else:
                    stringCopy = "Template Not Found!!"
                    stringCopyColor = 0xdc1076

            if doOverw:
                check = self.overWrite(finalPath)
                if not check == -1:
                    if check == None:
                        stringCopy = "Template Not Found!!"
                        stringCopyColor = 0xdc1076
                    else:
                        if check == True:
                            stringCopy = "Copy Done!"
                            stringCopyColor = 0x10dca1
                        else:
                            stringCopy = "Unable To Copy"
                            stringCopyColor = 0xdc1076
                    doOverw = False

            cvui.imshow(WINDOW_NAME, self.frame)
            char = cv.waitKey(1)
            self.frame[:] = (49, 52, 49)

            if (char == 27) or not cv.getWindowProperty(
                    WINDOW_NAME, cv.WND_PROP_VISIBLE):
                break
コード例 #6
0
def chooseVideoToTroubleshootSplitVideo(self, controller):

  # Choosing video to split

  if globalVariables["mac"]:
    self.videoToTroubleshootSplitVideo = filedialog.askopenfilename(initialdir = os.path.expanduser("~"),title = "Select video")
  else:
    self.videoToTroubleshootSplitVideo = filedialog.askopenfilename(initialdir = os.path.expanduser("~"),title = "Select video",filetypes = (("video","*.*"),("all files","*.*")))
  
  # User input of beginning and end of subvideo
  
  firstFrame = 1
  lastFrame  = 1000
  
  cap = cv2.VideoCapture(self.videoToTroubleshootSplitVideo)
  max_l = int(cap.get(7)) - 2
  
  cap.set(1, 1)
  ret, frame = cap.read()
  WINDOW_NAME = "Choose where the beginning of your sub-video should be."
  WINDOW_NAME_CTRL = "Control"
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0,0)
  cvui.init(WINDOW_NAME_CTRL)
  cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
  value = [1]
  curValue = value[0]
  buttonclicked = False
  widgetX = 40
  widgetY = 20
  widgetL = 300
  while not(buttonclicked):
      value[0] = int(value[0])
      if curValue != value[0]:
        cap.set(1, value[0])
        frameOld = frame
        ret, frame = cap.read()
        if not(ret):
          frame = frameOld
        curValue = value[0]
      frameCtrl = np.full((200, 750), 100).astype('uint8')
      frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0
      cvui.text(frameCtrl, widgetX, widgetY, 'Frame')
      cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, 0, max_l)
      cvui.counter(frameCtrl, widgetX, widgetY+60, value)
      buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the sub-video to start at this frame!")
      
      cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward')
      cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward')
      cvui.imshow(WINDOW_NAME, frame)
      cvui.imshow(WINDOW_NAME_CTRL, frameCtrl)
      r = cv2.waitKey(20)
      if (r == 54) or (r == 100) or (r == 0):
        value[0] = value[0] + 1
      elif (r == 52) or (r == 97) or (r == 113):
        value[0] = value[0] - 1
      elif (r == 103):
        value[0] = value[0] - 30
      elif (r == 104):
        value[0] = value[0] + 30
      elif (r == 102):
        value[0] = value[0] - 100
      elif (r == 106):
        value[0] = value[0] + 100
  cv2.destroyAllWindows()
  
  firstFrame = int(value[0])
  cap.set(1, max_l)
  ret, frame = cap.read()
  while not(ret):
    max_l = max_l - 1
    cap.set(1, max_l)
    ret, frame = cap.read()
  WINDOW_NAME = "Choose where the sub-video should end."
  WINDOW_NAME_CTRL = "Control"
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0,0)
  cvui.init(WINDOW_NAME_CTRL)
  cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
  value = [max_l]
  curValue = value[0]
  buttonclicked = False
  widgetX = 40
  widgetY = 20
  widgetL = 300
  while not(buttonclicked):
      value[0] = int(value[0])
      if curValue != value[0]:
        cap.set(1, value[0])
        frameOld = frame
        ret, frame = cap.read()
        if not(ret):
          frame = frameOld
        curValue = value[0]
      frameCtrl = np.full((200, 400), 100).astype('uint8')
      frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0
      cvui.text(frameCtrl, widgetX, widgetY, 'Frame')
      cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, firstFrame + 1, max_l-1)
      cvui.counter(frameCtrl, widgetX, widgetY+60, value)
      buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the sub-video to end at this frame!")
      cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward')
      cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward')
      cvui.imshow(WINDOW_NAME, frame)
      cvui.imshow(WINDOW_NAME_CTRL, frameCtrl)
      r = cv2.waitKey(20)
      if (r == 54) or (r == 100) or (r == 0):
        value[0] = value[0] + 1
      elif (r == 52) or (r == 97) or (r == 113):
        value[0] = value[0] - 1
      elif (r == 103):
        value[0] = value[0] - 30
      elif (r == 104):
        value[0] = value[0] + 30
      elif (r == 102):
        value[0] = value[0] - 100
      elif (r == 106):
        value[0] = value[0] + 100
  
  lastFrame = int(value[0])
  cv2.destroyAllWindows()
  cap.release()
  
  # Choosing directory to save sub-video
  directoryChosen = filedialog.askdirectory(title='Choose in which folder you want to save the sub-video.')
  
  # Extracting sub-video

  cap = cv2.VideoCapture(self.videoToTroubleshootSplitVideo)
  if (cap.isOpened()== False): 
    print("Error opening video stream or file")
    
  frame_width  = int(cap.get(3))
  frame_height = int(cap.get(4))
  xmin = 0
  xmax = frame_width
  ymin = 0
  ymax = frame_height

  out = cv2.VideoWriter(os.path.join(directoryChosen, 'subvideo.avi'), cv2.VideoWriter_fourcc('M','J','P','G'), 10, (xmax-xmin,ymax-ymin))
   
  i = firstFrame
  maxx = lastFrame
  cap.set(1, i)
  while(cap.isOpened() and (i<maxx)):
    i = i + 1
    ret, frame = cap.read()
    if ret == True:
      frame2 = frame[ymin:ymax,xmin:xmax]
      if False:
        frame2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
        frame2 = cv2.cvtColor(frame2, cv2.COLOR_GRAY2BGR)
      out.write(frame2)
    else: 
      break
  cap.release()

  self.show_frame("VideoToTroubleshootSplitVideo")
コード例 #7
0
ファイル: ddp.py プロジェクト: wasiqrumaney/DanceDancePose
def teach_step(posed='Images/yoga.jpg', Check=False):
    Estimator = TfPoseEstimator
    frame1 = np.zeros((768, 1024, 3), np.uint8)

    WINDOW1_NAME = 'Dance Dance Pose'
    cv2.namedWindow(WINDOW1_NAME)
    cvui.init(WINDOW1_NAME)

    inferred = infer(posed)
    original = cv2.imread(posed)

    #time.sleep(5)
    if original.shape[0] != 480 or original.shape[1] != 640:
        original = cv2.resize(original, (368, 368))

    if Check:
        cv2.imwrite('check.jpg', inferred)

    inferred = inferred - original
    #inferred=cv2.copyMakeBorder(inferred[:,int(np.nonzero(inferred)[1][0]/2):],0,0,0,int(np.nonzero(inferred)[1][0]/2),cv2.BORDER_REPLICATE)

    timeout = time.time() + 10
    capture = cv2.VideoCapture(0)
    counter = [time.time()]
    x = 1

    while True:
        cvui.context(WINDOW1_NAME)

        ret, frame = capture.read()

        gray = frame
        if gray.shape[0] != 4810 or gray.shape[1] != 640:
            gray = cv2.resize(gray, (368, 368))

        dst = cv2.addWeighted(inferred, 0.5, gray, 0.5, 0)
        frame1[:] = (49, 52, 49)
        cvui.beginRow(frame1, 10, 20, -1, -1, 30)

        cvui.image(dst)
        cvui.image(original)

        cvui.endRow()

        cvui.beginRow(frame1, 10, 400, -1, -1, 30)
        cvui.counter(frame1, 100, 410, counter, 0.1, '%.1f')
        counter = [timeout - time.time() for x in counter]
        cvui.text(frame1, 10, 410, "Tick tick")
        cvui.endRow()

        cvui.update(WINDOW1_NAME)
        cv2.imshow(WINDOW1_NAME, frame1)

        if cv2.waitKey(1) & 0xFF == ord('q') or time.time() > timeout:

            filename = 'captures/capture' + \
                      str(int(x)) + ".png"
            x = x + 1
            cv2.imwrite(filename, frame)
            break

    inferred_capture = infer(filename)
    original_inferred = cv2.imread(filename)

    if original_inferred.shape[0] != 4380 or original_inferred.shape[1] != 640:
        inferred_capture = cv2.resize(inferred_capture, (368, 368))
        original_inferred = cv2.resize(original_inferred, (368, 368))

    while True:
        final = cv2.addWeighted(inferred, 0.5, inferred_capture, 0.5, 0)
        cv2.imshow('final', final)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    diff_inferred = inferred_capture - original_inferred
    bw_inferred = cv2.cvtColor(diff_inferred, cv2.COLOR_BGR2GRAY)
    bw_inferred[bw_inferred >= 1] = 1
    bw_inferred[bw_inferred < 1] = 0

    bw_orig_inferred = cv2.cvtColor(inferred, cv2.COLOR_BGR2GRAY)
    bw_orig_inferred[bw_orig_inferred >= 1] = 1
    bw_orig_inferred[bw_orig_inferred < 1] = 0
    total = bw_orig_inferred == bw_inferred

    print('')
    print('')
    print('Overlap:' + str((1 - np.sum(total) / np.size(total)) * 10))
コード例 #8
0
def main():
    frame = np.zeros((600, 800, 3), np.uint8)

    # Create variables used by some components
    values = []
    checked = [False]
    checked2 = [False]
    value = [1.0]
    value2 = [1.0]
    value3 = [1.0]
    padding = 10
    img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR)
    imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR)
    imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR)

    # Fill the vector with a few random values
    for i in range(0, 20):
        values.append(random.uniform(0., 300.0))

    # Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
    cvui.init(WINDOW_NAME)

    while (True):
        # Fill the frame with a nice color
        frame[:] = (49, 52, 49)

        # In a row, all added elements are
        # horizontally placed, one next the other (from left to right)
        #
        # Within the cvui.beginRow() and cvui.endRow(),
        # all elements will be automatically positioned by cvui.
        #
        # Notice that all component calls within the begin/end block
        # DO NOT have (x,y) coordinates.
        #
        # Let's create a row at position (10,20) with width 100 and height 50.
        cvui.beginRow(frame, 10, 20, 100, 50)
        cvui.text('This is ')
        cvui.printf('a row')
        cvui.checkbox('checkbox', checked)
        cvui.window(80, 80, 'window')
        cvui.rect(50, 50, 0x00ff00, 0xff0000)
        cvui.sparkline(values, 50, 50)
        cvui.counter(value)
        cvui.button(100, 30, 'Fixed')
        cvui.image(img)
        cvui.button(img, imgGray, imgRed)
        cvui.endRow()

        # Here is another row, this time with a padding of 50px among components.
        padding = 50
        cvui.beginRow(frame, 10, 150, 100, 50, padding)
        cvui.text('This is ')
        cvui.printf('another row')
        cvui.checkbox('checkbox', checked2)
        cvui.window(80, 80, 'window')
        cvui.button(100, 30, 'Fixed')
        cvui.printf('with 50px padding.')
        cvui.endRow()

        # Another row mixing several components
        cvui.beginRow(frame, 10, 250, 100, 50)
        cvui.text('This is ')
        cvui.printf('another row with a trackbar ')
        #cvui.trackbar(150, &value2, 0., 5.);
        cvui.printf(' and a button ')
        cvui.button(100, 30, 'button')
        cvui.endRow()

        # In a column, all added elements are vertically placed,
        # one below the other, from top to bottom. Let's create
        # a column at (50, 300) with width 100 and height 200.
        cvui.beginColumn(frame, 50, 330, 100, 200)
        cvui.text('Column 1 (no padding)')
        cvui.button('button1')
        cvui.button('button2')
        cvui.text('End of column 1')
        cvui.endColumn()

        # Here is another column, using a padding value of 10,
        # which will add an space of 10px between each component.
        padding = 10
        cvui.beginColumn(frame, 300, 330, 100, 200, padding)
        cvui.text('Column 2 (padding = 10)')
        cvui.button('button1')
        cvui.button('button2')
        #cvui.trackbar(150, &value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25);
        cvui.text('End of column 2')
        cvui.endColumn()

        # You can also add an arbitrary amount of space between
        # components by calling cvui.space().
        #
        # cvui.space() is aware of context, so if it is used
        # within a beginColumn()/endColumn() block, the space will
        # be vertical. If it is used within a beginRow()/endRow()
        # block, space will be horizontal.
        cvui.beginColumn(frame, 550, 330, 100, 200)
        cvui.text('Column 3 (use space)')
        # Add 5 pixels of (vertical) space.
        cvui.space(5)
        cvui.button('button1 5px below')
        # Add 50 pixels of (vertical) space.
        cvui.space(50)
        cvui.text('Text 50px below')
        # Add 20 pixels of (vertical) space.
        cvui.space(20)
        cvui.button('Button 20px below')
        # Add 40 pixels of (vertical) space.
        cvui.space(40)
        cvui.text('End of column 2 (40px below)')
        cvui.endColumn()

        # This function must be called *AFTER* all UI components. It does
        # all the behind the scenes magic to handle mouse clicks, etc.
        cvui.update()

        # Show everything on the screen
        cv2.imshow(WINDOW_NAME, frame)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
コード例 #9
0
ファイル: main-app.py プロジェクト: Dovyski/cvui
def main():
	frame = np.zeros((300, 600, 3), np.uint8)
	checked = [False]
	checked2 = [True]
	count = [0]
	countFloat = [0.0]
	trackbarValue = [0.0]

	# Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
	cvui.init(WINDOW_NAME)

	while (True):
		# Fill the frame with a nice color
		frame[:] = (49, 52, 49)

		# Show some pieces of text.
		cvui.text(frame, 50, 30, 'Hey there!')
		
		# You can also specify the size of the text and its color
		# using hex 0xRRGGBB CSS-like style.
		cvui.text(frame, 200, 30, 'Use hex 0xRRGGBB colors easily', 0.4, 0xff0000)
		
		# Sometimes you want to show text that is not that simple, e.g. strings + numbers.
		# You can use cvui.printf for that. It accepts a variable number of parameter, pretty
		# much like printf does.
		cvui.printf(frame, 200, 50, 0.4, 0x00ff00, 'Use printf formatting: %d + %.2f = %f', 2, 3.2, 5.2)

		# Buttons will return true if they were clicked, which makes
		# handling clicks a breeze.
		if cvui.button(frame, 50, 60, 'Button'):
			print('Button clicked')

		# If you do not specify the button width/height, the size will be
		# automatically adjusted to properly house the label.
		cvui.button(frame, 200, 70, 'Button with large label')
		
		# You can tell the width and height you want
		cvui.button(frame, 410, 70, 15, 15, 'x')

		# Window components are useful to create HUDs and similars. At the
		# moment, there is no implementation to constraint content within a
		# a window.
		cvui.window(frame, 50, 120, 120, 100, 'Window')
		
		# The counter component can be used to alter int variables. Use
		# the 4th parameter of the function to point it to the variable
		# to be changed.
		cvui.counter(frame, 200, 120, count)

		# Counter can be used with doubles too. You can also specify
		# the counter's step (how much it should change
		# its value after each button press), as well as the format
		# used to print the value.
		cvui.counter(frame, 320, 120, countFloat, 0.1, '%.1f')

		# The trackbar component can be used to create scales.
		# It works with all numerical types (including chars).
		cvui.trackbar(frame, 420, 110, 150, trackbarValue, 0., 50.)
		
		# Checkboxes also accept a pointer to a variable that controls
		# the state of the checkbox (checked or not). cvui.checkbox() will
		# automatically update the value of the boolean after all
		# interactions, but you can also change it by yourself. Just
		# do "checked = [True]" somewhere and the checkbox will change
		# its appearance.
		cvui.checkbox(frame, 200, 160, 'Checkbox', checked)
		cvui.checkbox(frame, 200, 190, 'A checked checkbox', checked2)

		# Display the lib version at the bottom of the screen
		cvui.printf(frame, 600 - 80, 300 - 20, 0.4, 0xCECECE, 'cvui v.%s', cvui.VERSION)

		# This function must be called *AFTER* all UI components. It does
		# all the behind the scenes magic to handle mouse clicks, etc.
		cvui.update()

		# Show everything on the screen
		cv2.imshow(WINDOW_NAME, frame)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
コード例 #10
0
def main():
    # We have one mat for each window.
    frame1 = np.zeros((600, 800, 3), np.uint8)
    frame2 = np.zeros((600, 800, 3), np.uint8)

    # Create variables used by some components
    window1_values = []
    window2_values = []
    window1_checked = [False]
    window1_checked2 = [False]
    window2_checked = [False]
    window2_checked2 = [False]
    window1_value = [1.0]
    window1_value2 = [1.0]
    window1_value3 = [1.0]
    window2_value = [1.0]
    window2_value2 = [1.0]
    window2_value3 = [1.0]

    img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR)
    imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR)
    imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR)

    padding = 10

    # Fill the vector with a few random values
    for i in range(0, 20):
        window1_values.append(random.uniform(0., 300.0))
        window2_values.append(random.uniform(0., 300.0))

    # Start two OpenCV windows
    cv2.namedWindow(WINDOW1_NAME)
    cv2.namedWindow(WINDOW2_NAME)

    # Init cvui and inform it to use the first window as the default one.
    # cvui.init() will automatically watch the informed window.
    cvui.init(WINDOW1_NAME)

    # Tell cvui to keep track of mouse events in window2 as well.
    cvui.watch(WINDOW2_NAME)

    while (True):
        # Inform cvui that all subsequent component calls and events are related to window 1.
        cvui.context(WINDOW1_NAME)

        # Fill the frame with a nice color
        frame1[:] = (49, 52, 49)

        cvui.beginRow(frame1, 10, 20, 100, 50)
        cvui.text('This is ')
        cvui.printf('a row')
        cvui.checkbox('checkbox', window1_checked)
        cvui.window(80, 80, 'window')
        cvui.rect(50, 50, 0x00ff00, 0xff0000)
        cvui.sparkline(window1_values, 50, 50)
        cvui.counter(window1_value)
        cvui.button(100, 30, 'Fixed')
        cvui.image(img)
        cvui.button(img, imgGray, imgRed)
        cvui.endRow()

        padding = 50
        cvui.beginRow(frame1, 10, 150, 100, 50, padding)
        cvui.text('This is ')
        cvui.printf('another row')
        cvui.checkbox('checkbox', window1_checked2)
        cvui.window(80, 80, 'window')
        cvui.button(100, 30, 'Fixed')
        cvui.printf('with 50px paddin7hg.')
        cvui.endRow()

        cvui.beginRow(frame1, 10, 250, 100, 50)
        cvui.text('This is ')
        cvui.printf('another row with a trackbar ')
        cvui.trackbar(150, window1_value2, 0., 5.)
        cvui.printf(' and a button ')
        cvui.button(100, 30, 'button')
        cvui.endRow()

        cvui.beginColumn(frame1, 50, 330, 100, 200)
        cvui.text('Column 1 (no padding)')
        cvui.button('button1')
        cvui.button('button2')
        cvui.text('End of column 1')
        cvui.endColumn()

        padding = 10
        cvui.beginColumn(frame1, 300, 330, 100, 200, padding)
        cvui.text('Column 2 (padding = 10)')
        cvui.button('button1')
        cvui.button('button2')
        cvui.trackbar(150, window1_value3, 0., 5., 1, '%3.2Lf',
                      cvui.TRACKBAR_DISCRETE, 0.25)
        cvui.text('End of column 2')
        cvui.endColumn()

        cvui.beginColumn(frame1, 550, 330, 100, 200)
        cvui.text('Column 3 (use space)')
        cvui.space(5)
        cvui.button('button1 5px below')
        cvui.space(50)
        cvui.text('Text 50px below')
        cvui.space(20)
        cvui.button('Button 20px below')
        cvui.space(40)
        cvui.text('End of column 2 (40px below)')
        cvui.endColumn()

        # Update all components of window1, e.g. mouse clicks, and show it.
        cvui.update(WINDOW1_NAME)
        cv2.imshow(WINDOW1_NAME, frame1)

        # From this point on, we are going to render the second window. We need to inform cvui
        # that all updates and components from now on are connected to window 2.
        # We do that by calling cvui.context().
        cvui.context(WINDOW2_NAME)
        frame2[:] = (49, 52, 49)

        cvui.beginRow(frame2, 10, 20, 100, 50)
        cvui.text('This is ')
        cvui.printf('a row')
        cvui.checkbox('checkbox', window2_checked)
        cvui.window(80, 80, 'window')
        cvui.rect(50, 50, 0x00ff00, 0xff0000)
        cvui.sparkline(window2_values, 50, 50)
        cvui.counter(window2_value)
        cvui.button(100, 30, 'Fixed')
        cvui.image(img)
        cvui.button(img, imgGray, imgRed)
        cvui.endRow()

        padding = 50
        cvui.beginRow(frame2, 10, 150, 100, 50, padding)
        cvui.text('This is ')
        cvui.printf('another row')
        cvui.checkbox('checkbox', window2_checked2)
        cvui.window(80, 80, 'window')
        cvui.button(100, 30, 'Fixed')
        cvui.printf('with 50px paddin7hg.')
        cvui.endRow()

        # Another row mixing several components
        cvui.beginRow(frame2, 10, 250, 100, 50)
        cvui.text('This is ')
        cvui.printf('another row with a trackbar ')
        cvui.trackbar(150, window2_value2, 0., 5.)
        cvui.printf(' and a button ')
        cvui.button(100, 30, 'button')
        cvui.endRow()

        cvui.beginColumn(frame2, 50, 330, 100, 200)
        cvui.text('Column 1 (no padding)')
        cvui.button('button1')
        cvui.button('button2')
        cvui.text('End of column 1')
        cvui.endColumn()

        padding = 10
        cvui.beginColumn(frame2, 300, 330, 100, 200, padding)
        cvui.text('Column 2 (padding = 10)')
        cvui.button('button1')
        cvui.button('button2')
        cvui.trackbar(150, window2_value3, 0., 5., 1, '%3.2Lf',
                      cvui.TRACKBAR_DISCRETE, 0.25)
        cvui.text('End of column 2')
        cvui.endColumn()

        cvui.beginColumn(frame2, 550, 330, 100, 200)
        cvui.text('Column 3 (use space)')
        cvui.space(5)
        cvui.button('button1 5px below')
        cvui.space(50)
        cvui.text('Text 50px below')
        cvui.space(20)
        cvui.button('Button 20px below')
        cvui.space(40)
        cvui.text('End of column 2 (40px below)')
        cvui.endColumn()

        # Update all components of window2, e.g. mouse clicks, and show it.
        cvui.update(WINDOW2_NAME)
        cv2.imshow(WINDOW2_NAME, frame2)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
コード例 #11
0
def main():
	# We have one mat for each window.
	frame1 = np.zeros((600, 800, 3), np.uint8)
	frame2 = np.zeros((600, 800, 3), np.uint8)

	# Create variables used by some components
	window1_values = []
	window2_values = []
	window1_checked = [False]
	window1_checked2 = [False]
	window2_checked = [False]
	window2_checked2 = [False]
	window1_value = [1.0]
	window1_value2 = [1.0]
	window1_value3 = [1.0]
	window2_value = [1.0]
	window2_value2 = [1.0]
	window2_value3 = [1.0]

	img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR)
	imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR)
	imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR)

	padding = 10

	# Fill the vector with a few random values
	for i in range(0, 20):
		window1_values.append(random.uniform(0., 300.0))
		window2_values.append(random.uniform(0., 300.0))

	# Start two OpenCV windows
	cv2.namedWindow(WINDOW1_NAME)
	cv2.namedWindow(WINDOW2_NAME)
	
	# Init cvui and inform it to use the first window as the default one.
	# cvui.init() will automatically watch the informed window.
	cvui.init(WINDOW1_NAME)

	# Tell cvui to keep track of mouse events in window2 as well.
	cvui.watch(WINDOW2_NAME)

	while (True):
		# Inform cvui that all subsequent component calls and events are related to window 1.
		cvui.context(WINDOW1_NAME)

		# Fill the frame with a nice color
		frame1[:] = (49, 52, 49)

		cvui.beginRow(frame1, 10, 20, 100, 50)
		cvui.text('This is ')
		cvui.printf('a row')
		cvui.checkbox('checkbox', window1_checked)
		cvui.window(80, 80, 'window')
		cvui.rect(50, 50, 0x00ff00, 0xff0000)
		cvui.sparkline(window1_values, 50, 50)
		cvui.counter(window1_value)
		cvui.button(100, 30, 'Fixed')
		cvui.image(img)
		cvui.button(img, imgGray, imgRed)
		cvui.endRow()

		padding = 50
		cvui.beginRow(frame1, 10, 150, 100, 50, padding)
		cvui.text('This is ')
		cvui.printf('another row')
		cvui.checkbox('checkbox', window1_checked2)
		cvui.window(80, 80, 'window')
		cvui.button(100, 30, 'Fixed')
		cvui.printf('with 50px paddin7hg.')
		cvui.endRow()

		cvui.beginRow(frame1, 10, 250, 100, 50)
		cvui.text('This is ')
		cvui.printf('another row with a trackbar ')
		cvui.trackbar(150, window1_value2, 0., 5.)
		cvui.printf(' and a button ')
		cvui.button(100, 30, 'button')
		cvui.endRow()

		cvui.beginColumn(frame1, 50, 330, 100, 200)
		cvui.text('Column 1 (no padding)')
		cvui.button('button1')
		cvui.button('button2')
		cvui.text('End of column 1')
		cvui.endColumn()

		padding = 10
		cvui.beginColumn(frame1, 300, 330, 100, 200, padding)
		cvui.text('Column 2 (padding = 10)')
		cvui.button('button1')
		cvui.button('button2')
		cvui.trackbar(150, window1_value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25)
		cvui.text('End of column 2')
		cvui.endColumn()

		cvui.beginColumn(frame1, 550, 330, 100, 200)
		cvui.text('Column 3 (use space)')
		cvui.space(5)
		cvui.button('button1 5px below')
		cvui.space(50)
		cvui.text('Text 50px below')
		cvui.space(20)
		cvui.button('Button 20px below')
		cvui.space(40)
		cvui.text('End of column 2 (40px below)')
		cvui.endColumn()
		
		# Update all components of window1, e.g. mouse clicks, and show it.
		cvui.update(WINDOW1_NAME)
		cv2.imshow(WINDOW1_NAME, frame1)
		
		# From this point on, we are going to render the second window. We need to inform cvui
		# that all updates and components from now on are connected to window 2.
		# We do that by calling cvui.context().
		cvui.context(WINDOW2_NAME)
		frame2[:] = (49, 52, 49)
		
		cvui.beginRow(frame2, 10, 20, 100, 50)
		cvui.text('This is ')
		cvui.printf('a row')
		cvui.checkbox('checkbox', window2_checked)
		cvui.window(80, 80, 'window')
		cvui.rect(50, 50, 0x00ff00, 0xff0000)
		cvui.sparkline(window2_values, 50, 50)
		cvui.counter(window2_value)
		cvui.button(100, 30, 'Fixed')
		cvui.image(img)
		cvui.button(img, imgGray, imgRed)
		cvui.endRow()
		
		padding = 50
		cvui.beginRow(frame2, 10, 150, 100, 50, padding)
		cvui.text('This is ')
		cvui.printf('another row')
		cvui.checkbox('checkbox', window2_checked2)
		cvui.window(80, 80, 'window')
		cvui.button(100, 30, 'Fixed')
		cvui.printf('with 50px paddin7hg.')
		cvui.endRow()
		
		# Another row mixing several components 
		cvui.beginRow(frame2, 10, 250, 100, 50)
		cvui.text('This is ')
		cvui.printf('another row with a trackbar ')
		cvui.trackbar(150, window2_value2, 0., 5.)
		cvui.printf(' and a button ')
		cvui.button(100, 30, 'button')
		cvui.endRow()

		cvui.beginColumn(frame2, 50, 330, 100, 200)
		cvui.text('Column 1 (no padding)')
		cvui.button('button1')
		cvui.button('button2')
		cvui.text('End of column 1')
		cvui.endColumn()
		
		padding = 10
		cvui.beginColumn(frame2, 300, 330, 100, 200, padding)
		cvui.text('Column 2 (padding = 10)')
		cvui.button('button1')
		cvui.button('button2')
		cvui.trackbar(150, window2_value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25)
		cvui.text('End of column 2')
		cvui.endColumn()

		cvui.beginColumn(frame2, 550, 330, 100, 200)
		cvui.text('Column 3 (use space)')
		cvui.space(5)
		cvui.button('button1 5px below')
		cvui.space(50)
		cvui.text('Text 50px below')
		cvui.space(20)
		cvui.button('Button 20px below')
		cvui.space(40)
		cvui.text('End of column 2 (40px below)')
		cvui.endColumn()
		
		# Update all components of window2, e.g. mouse clicks, and show it.
		cvui.update(WINDOW2_NAME)
		cv2.imshow(WINDOW2_NAME, frame2)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
コード例 #12
0
            cvui.image(frame, 20, 20, printScreen)

        if cvui.button(frame, 400, 400, "Select window"):
            if run_button == 0:
                run_button = 1

            if run_button == 1:
                run_button = 0
                titlee = program_list[0]

        if run_button2 == 0:
            cvui.text(frame, 10, 305, "Capture Area")
            cvui.text(frame, 10, 355, "Min Max")

            cvui.text(frame, 100, 285, "Starting")
            cvui.counter(frame, 100, 300, Starting, 10)
            cvui.text(frame, 200, 285, "Width")
            cvui.counter(frame, 200, 300, area_width, 10)
            cvui.text(frame, 300, 285, "Height")
            cvui.counter(frame, 300, 300, area_height, 10)
            cvui.text(frame, 100, 335, "Max")
            cvui.counter(frame, 100, 350, cap_max, 100)
            cvui.text(frame, 200, 335, "Min")
            cvui.counter(frame, 200, 350, cap_min, 100)
            cvui.text(frame, 300, 335, "sensitivity")
            cvui.counter(frame, 300, 350, sensitivity, 1)
            cvui.window(frame, 30, 390, 360, 100, "Log")
            cvui.printf(frame, 50, 420, 0.6, 0xffffff, "Success: %d",
                        success_num)

        # cvui.update()
コード例 #13
0
def printStuffOnCtrlImg(frameCtrl, frameNum, x, y, l, minn, maxx, name):
    cvui.text(frameCtrl, x, y, name)
    cvui.trackbar(frameCtrl, x, y + 10, l, frameNum, minn, maxx)
    cvui.counter(frameCtrl, x + l + 10, y + 20, frameNum)
コード例 #14
0
def chooseBeginningAndEndOfVideo(self, controller):
    cap = cv2.VideoCapture(self.videoToCreateConfigFileFor)
    max_l = int(cap.get(7)) - 2

    cap.set(1, 1)
    ret, frame = cap.read()
    WINDOW_NAME = "Choose where the analysis of your video should start."
    WINDOW_NAME_CTRL = "Control"
    cvui.init(WINDOW_NAME)
    cv2.moveWindow(WINDOW_NAME, 0, 0)
    cvui.init(WINDOW_NAME_CTRL)
    cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
    value = [1]
    curValue = value[0]
    buttonclicked = False
    buttonEntireVideo = False
    widgetX = 40
    widgetY = 20
    widgetL = 300
    while not (buttonclicked) and not (buttonEntireVideo):
        value[0] = int(value[0])
        if curValue != value[0]:
            cap.set(1, value[0])
            frameOld = frame
            ret, frame = cap.read()
            if not (ret):
                frame = frameOld
            curValue = value[0]
        frameCtrl = np.full((200, 750), 100).astype('uint8')
        frameCtrl[widgetY:widgetY + 60, widgetX:widgetX + widgetL] = 0
        cvui.text(frameCtrl, widgetX, widgetY, 'Frame')
        cvui.trackbar(frameCtrl, widgetX, widgetY + 10, widgetL, value, 0,
                      max_l)
        cvui.counter(frameCtrl, widgetX, widgetY + 60, value)
        buttonclicked = cvui.button(
            frameCtrl, widgetX, widgetY + 90,
            "Ok, I want the tracking to start at this frame!")

        cvui.text(frameCtrl, widgetX + 350, widgetY + 1,
                  'No, this is unecessary:')
        buttonEntireVideo = cvui.button(
            frameCtrl, widgetX + 350, widgetY + 40,
            "I want the tracking to run on the entire video!")

        cvui.text(frameCtrl, widgetX, widgetY + 130,
                  'Keys: 4 or a: move backwards; 6 or d: move forward')
        cvui.text(frameCtrl, widgetX, widgetY + 160,
                  'Keys: g or f: fast backwards; h or j: fast forward')
        cvui.imshow(WINDOW_NAME, frame)
        cvui.imshow(WINDOW_NAME_CTRL, frameCtrl)
        r = cv2.waitKey(20)
        if (r == 54) or (r == 100) or (r == 0):
            value[0] = value[0] + 1
        elif (r == 52) or (r == 97) or (r == 113):
            value[0] = value[0] - 1
        elif (r == 103):
            value[0] = value[0] - 30
        elif (r == 104):
            value[0] = value[0] + 30
        elif (r == 102):
            value[0] = value[0] - 100
        elif (r == 106):
            value[0] = value[0] + 100
    cv2.destroyAllWindows()

    if not (buttonEntireVideo):
        self.configFile["firstFrame"] = int(value[0])
        cap.set(1, max_l)
        ret, frame = cap.read()
        while not (ret):
            max_l = max_l - 1
            cap.set(1, max_l)
            ret, frame = cap.read()
        WINDOW_NAME = "Choose where the analysis of your video should end."
        WINDOW_NAME_CTRL = "Control"
        cvui.init(WINDOW_NAME)
        cv2.moveWindow(WINDOW_NAME, 0, 0)
        cvui.init(WINDOW_NAME_CTRL)
        cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
        value = [max_l]
        curValue = value[0]
        buttonclicked = False
        widgetX = 40
        widgetY = 20
        widgetL = 300
        while not (buttonclicked):
            value[0] = int(value[0])
            if curValue != value[0]:
                cap.set(1, value[0])
                frameOld = frame
                ret, frame = cap.read()
                if not (ret):
                    frame = frameOld
                curValue = value[0]
            frameCtrl = np.full((200, 400), 100).astype('uint8')
            frameCtrl[widgetY:widgetY + 60, widgetX:widgetX + widgetL] = 0
            cvui.text(frameCtrl, widgetX, widgetY, 'Frame')
            cvui.trackbar(frameCtrl, widgetX, widgetY + 10, widgetL, value, 0,
                          max_l - 1)
            cvui.counter(frameCtrl, widgetX, widgetY + 60, value)
            buttonclicked = cvui.button(
                frameCtrl, widgetX, widgetY + 90,
                "Ok, I want the tracking to end at this frame!")
            cvui.text(frameCtrl, widgetX, widgetY + 130,
                      'Keys: 4 or a: move backwards; 6 or d: move forward')
            cvui.text(frameCtrl, widgetX, widgetY + 160,
                      'Keys: g or f: fast backwards; h or j: fast forward')
            cvui.imshow(WINDOW_NAME, frame)
            cvui.imshow(WINDOW_NAME_CTRL, frameCtrl)
            r = cv2.waitKey(20)
            if (r == 54) or (r == 100) or (r == 0):
                value[0] = value[0] + 1
            elif (r == 52) or (r == 97) or (r == 113):
                value[0] = value[0] - 1
            elif (r == 103):
                value[0] = value[0] - 30
            elif (r == 104):
                value[0] = value[0] + 30
            elif (r == 102):
                value[0] = value[0] - 100
            elif (r == 106):
                value[0] = value[0] + 100
        self.configFile["lastFrame"] = int(value[0])
        cv2.destroyAllWindows()

    if int(self.configFile["headEmbeded"]) == 1:
        controller.show_frame("HeadEmbeded")
    else:
        if self.organism == 'zebrafishNew':
            controller.show_frame("NumberOfAnimals2")
        elif self.organism == 'zebrafish':
            controller.show_frame("NumberOfAnimals")
        else:
            controller.show_frame("NumberOfAnimalsCenterOfMass")
コード例 #15
0
def param(frame, x, y, width, value, min, max, name, step=1):
    cvui.text(frame, x, y, name)
    cvui.counter(frame, x, y + 13, value, step, "%.0Lf")
    cvui.trackbar(frame, x + 100, y, width, value, min, max, 0, '%.0Lf',
                  cvui.TRACKBAR_DISCRETE, step)
    value[0] = np.clip(value[0], min, max).astype(type(value[0]))
コード例 #16
0
ファイル: row-column.py プロジェクト: Dovyski/cvui
def main():
	frame = np.zeros((600, 800, 3), np.uint8)
	
	# Create variables used by some components
	values = []
	checked = [False]
	checked2 = [False]
	value = [1.0]
	value2 = [1.0]
	value3 = [1.0]
	padding = 10
	img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR)
	imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR)
	imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR)

	# Fill the vector with a few random values
	for i in range(0, 20):
		values.append(random.uniform(0., 300.0))
	
	# Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
	cvui.init(WINDOW_NAME)

	while (True):
		# Fill the frame with a nice color
		frame[:] = (49, 52, 49)

		# In a row, all added elements are
		# horizontally placed, one next the other (from left to right)
		#
		# Within the cvui.beginRow() and cvui.endRow(),
		# all elements will be automatically positioned by cvui.
		# 
		# Notice that all component calls within the begin/end block
		# DO NOT have (x,y) coordinates. 
		#
		# Let's create a row at position (10,20) with width 100 and height 50.
		cvui.beginRow(frame, 10, 20, 100, 50)
		cvui.text('This is ')
		cvui.printf('a row')
		cvui.checkbox('checkbox', checked)
		cvui.window(80, 80, 'window')
		cvui.rect(50, 50, 0x00ff00, 0xff0000);
		cvui.sparkline(values, 50, 50);
		cvui.counter(value)
		cvui.button(100, 30, 'Fixed')
		cvui.image(img)
		cvui.button(img, imgGray, imgRed)
		cvui.endRow()

		# Here is another row, this time with a padding of 50px among components.
		padding = 50;
		cvui.beginRow(frame, 10, 150, 100, 50, padding)
		cvui.text('This is ')
		cvui.printf('another row')
		cvui.checkbox('checkbox', checked2)
		cvui.window(80, 80, 'window')
		cvui.button(100, 30, 'Fixed')
		cvui.printf('with 50px padding.')
		cvui.endRow()

		# Another row mixing several components 
		cvui.beginRow(frame, 10, 250, 100, 50)
		cvui.text('This is ')
		cvui.printf('another row with a trackbar ')
		#cvui.trackbar(150, &value2, 0., 5.);
		cvui.printf(' and a button ')
		cvui.button(100, 30, 'button')
		cvui.endRow()

		# In a column, all added elements are vertically placed,
		# one below the other, from top to bottom. Let's create
		# a column at (50, 300) with width 100 and height 200.
		cvui.beginColumn(frame, 50, 330, 100, 200)
		cvui.text('Column 1 (no padding)')
		cvui.button('button1')
		cvui.button('button2')
		cvui.text('End of column 1')
		cvui.endColumn()

		# Here is another column, using a padding value of 10,
		# which will add an space of 10px between each component.
		padding = 10
		cvui.beginColumn(frame, 300, 330, 100, 200, padding)
		cvui.text('Column 2 (padding = 10)')
		cvui.button('button1')
		cvui.button('button2')
		#cvui.trackbar(150, &value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25);
		cvui.text('End of column 2')
		cvui.endColumn()

		# You can also add an arbitrary amount of space between
		# components by calling cvui.space().
		#
		# cvui.space() is aware of context, so if it is used
		# within a beginColumn()/endColumn() block, the space will
		# be vertical. If it is used within a beginRow()/endRow()
		# block, space will be horizontal.
		cvui.beginColumn(frame, 550, 330, 100, 200)
		cvui.text('Column 3 (use space)')
		# Add 5 pixels of (vertical) space.
		cvui.space(5)
		cvui.button('button1 5px below')
		# Add 50 pixels of (vertical) space. 
		cvui.space(50)
		cvui.text('Text 50px below')
		# Add 20 pixels of (vertical) space.
		cvui.space(20)
		cvui.button('Button 20px below')
		# Add 40 pixels of (vertical) space.
		cvui.space(40)
		cvui.text('End of column 2 (40px below)')
		cvui.endColumn()

		# This function must be called *AFTER* all UI components. It does
		# all the behind the scenes magic to handle mouse clicks, etc.
		cvui.update()

		# Show everything on the screen
		cv2.imshow(WINDOW_NAME, frame)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break