def __init__(self): self.dump = False self.move = None self.setAngle = None self.initWindows() self.cam = cv.CaptureFromCAM(0) skin_detector = skin.SkinDetector() motion_util = motion2.MotionUtility() cv.CreateTrackbar('l_hueThreshold', self.proc_win_name, SDC.GSD_HUE_LT, 255, skin_detector.setHueThresholdLow) cv.CreateTrackbar('h_hueThreshold', self.proc_win_name, SDC.GSD_HUE_UT, 255, skin_detector.setHueThresholdHigh) cv.CreateTrackbar('l_SaturationThreshold', self.proc_win_name, SDC.GSD_INTENSITY_LT, 255, skin_detector.setIntensityThresholdLow) cv.CreateTrackbar('h_SaturationThreshold', self.proc_win_name, SDC.GSD_INTENSITY_UT, 255, skin_detector.setIntensityThresholdHigh) self.session = ImageProcessSession(skin_detector, motion_util, self) img = cv.QueryFrame(self.cam) img = im.resize(img, width=400) self.session.set_size(img)
def get_tracked_region(im): tr = TrackedRegion(im) cv.NamedWindow("reference") cv.CreateTrackbar('xpos', 'reference', 0, im.width - 1, tr.set_x) cv.CreateTrackbar('ypos', 'reference', 0, im.height - 1, tr.set_y) cv.CreateTrackbar('size', 'reference', 0, im.width - 1, tr.set_size) # Show position of descriptors on reference image cv.ShowImage("reference", im) # Selecting tracked region while True: key_pressed = cv.WaitKey(100) if key_pressed == 32: cv.Rectangle(im, (tr.xpos, tr.ypos), (tr.xpos + tr.size, tr.ypos + tr.size), 255, thickness=3) cv.DestroyWindow("reference") break elif key_pressed == 27: cv.DestroyAllWindows() cv.WaitKey(100) return else: im_copy = cv.CreateMat(im.height, im.width, cv.CV_8UC1) cv.Copy(im, im_copy) cv.Rectangle(im_copy, (tr.xpos, tr.ypos), (tr.xpos + tr.size, tr.ypos + tr.size), 255, thickness=3) cv.ShowImage("reference", im_copy) return tr
def run(self): cv.NamedWindow("Threshold", 1) cv.ShowImage("Threshold", image) cv.CreateTrackbar("tLetter", "Threshold", self.tLetter, 255, self.onChangeLetter) cv.CreateTrackbar("rBright", "Threshold", self.rBright, 255, self.onChangeBright) self.reDraw() cv.WaitKey(0)
def __init__(self): frame = 211 self.tolerancia = 35 cv.CreateTrackbar("Frames", "Video", frame, frames_total - 1, self.atualiza_frame) cv.CreateTrackbar("Tolerancia", "Video", self.tolerancia, 255, self.atualiza_tolerancia) self.atualiza_frame(frame)
def __init__(self, files, target): cv.NamedWindow('preview', 1) cv.CreateTrackbar('t-low', 'preview', 35, 254, self.changeThresholdMin) cv.CreateTrackbar('t-upper', 'preview', 220, 254, self.changeThresholdMax) cv.SetMouseCallback('preview', self.onMouseEvent) self.files = files self.target = target self.step = 360.000 / len(files) self.run()
def __init__(self, img0): self.thresh1 = 255 self.thresh2 = 30 self.level =4 self.storage = cv.CreateMemStorage() cv.NamedWindow("Source", 0) cv.ShowImage("Source", img0) cv.NamedWindow("Segmentation", 0) cv.CreateTrackbar("Thresh1", "Segmentation", self.thresh1, 255, self.set_thresh1) cv.CreateTrackbar("Thresh2", "Segmentation", self.thresh2, 255, self.set_thresh2) self.image0 = cv.CloneImage(img0) self.image1 = cv.CloneImage(img0) cv.ShowImage("Segmentation", self.image1)
def __init__(self): imagem_de_fundo = cv.LoadImage(caminho_para_foto) cv.NamedWindow(titulo_janela, 1) cv.MoveWindow(titulo_janela, 400, 50) cv.CreateTrackbar(nome_jogador_1, titulo_janela, vida_jogador_1, 30, self.atualiza_vida_jogador_1) cv.CreateTrackbar(nome_jogador_2, titulo_janela, vida_jogador_2, 30, self.atualiza_vida_jogador_2) self.atualiza_vida_jogador_1(vida_jogador_1) self.atualiza_vida_jogador_2(vida_jogador_2) cv.ShowImage(titulo_janela, imagem_de_fundo)
def __init__(self, files, target): cv.NamedWindow('preview', 1) cv.CreateTrackbar('t-low', 'preview', self.thresholdMin, 256, self.changeThresholdMin) cv.CreateTrackbar('t-upper', 'preview', self.thresholdMax, 256, self.changeThresholdMax) #cv.CreateTrackbar('c-size', 'preview', self.contourSize, 100000, self.changeContoursize ) cv.SetMouseCallback('preview', self.onMouseEvent) self.files = files self.target = target self.step = 360.000 / len(files) self.run()
def toggle_threshold_window(value): global threshold_window #window is opened and has to be closed if threshold_window == 1 and value == 0: cv.DestroyWindow('Threshold') threshold_window = 0 elif threshold_window == 0 and value == 1: cv.NamedWindow('Threshold') cv.CreateTrackbar('threshold', 'Threshold', threshold, 500, change_threshold) cv.CreateTrackbar('depth', 'Threshold', current_depth, 2048, change_depth) threshold_window = 1
def __init__( self, files, target ): cv.NamedWindow('preview', 1) cv.CreateTrackbar('threshold low', 'preview', self.thresholdMin, 256, self.changeThresholdMin ) cv.CreateTrackbar('threshold high', 'preview', self.thresholdMax, 256, self.changeThresholdMax ) cv.CreateTrackbar('offset center', 'preview', 100, 200, self.changeCenterOffset ) #cv.CreateTrackbar('c-size', 'preview', self.contourSize, 100000, self.changeContoursize ) cv.SetMouseCallback( 'preview', self.onMouseEvent ) self.files = files self.target = target self.step = math.radians(360.000 / len(files)) self.angles = [radians(i*(360.00/len(files))) for i in range(0,len(files))] self.run();
def main(): print "hello world" capture = cv.CreateCameraCapture(0) cv.NamedWindow("test", 1) cv.NamedWindow("result", 1) global h_lower, h_upper, s_lower, s_upper cv.CreateTrackbar("hlow", "result", h_lower, 256, on_track_bar_hlow) cv.CreateTrackbar("hhigh", "result", h_upper, 256, on_track_bar_hhigh) cv.CreateTrackbar("slow", "result", s_lower, 256, on_track_bar_slow) cv.CreateTrackbar("shigh", "result", s_upper, 256, on_track_bar_shigh) while True: image = cv.QueryFrame(capture) get_hand(image) cv.ShowImage("test", image) if(cv.WaitKey(10) != -1): break
def execute(name, total): min = self.render_args[name][0] steps = self.render_args[name][2] self._tb.append( cv.CreateTrackbar(name, self.title, (self.args[name] - (min - 1)) / steps - 1, total, lambda x: self.update_arg(name, x)))
def __init__(self, imagem_cinza): self.imagem_cinza = imagem_cinza versao = 0 cv.NamedWindow("Foto Cinza", 1) cv.NamedWindow("Foto Filtrada", 1) cv.ShowImage("Foto Cinza", imagem_cinza) cv.CreateTrackbar("Filtros", "Foto Cinza", 0, 7, self.atualiza_matriz) self.atualiza_matriz(versao)
def __init__(self, cModel): self.model = cModel windowName = "Fisheye" cv.NamedWindow(windowName,cv.CV_WINDOW_NORMAL) cv.NamedWindow('Image') cv.MoveWindow('Image',1,220) x,y = self.model.res cv.CreateTrackbar ("Threshold", windowName, 1, 100, self.onThresholdChange) cv.CreateTrackbar ("Horizon", windowName, 10, min(self.model.res)/2, self.onRadiusChange) cv.CreateTrackbar ("North", windowName, 90, 360, self.onNorthChange) cv.CreateTrackbar ('x', windowName, x/2, x, self.on_Xchange) cv.CreateTrackbar ('y', windowName, y/2, y, self.on_Ychange) cv.ResizeWindow(windowName, 1200,200) self.onThresholdChange (0)
def __init__(self): self.LoadIniData() self.source = Source(self.cameraid) self.storage = cv.CreateMemStorage(0) self.orig = self.source.grab_frame() self.last = 0 self.old_center = (0, 0) self.width = self.orig.width self.height = self.orig.height self.size = (self.width, self.height) self.smallheight = self.working_height self.smallwidth = int(self.width * self.smallheight / self.height * 1.0) self.smallsize = (self.smallwidth, self.smallheight) # alloc mem for images used at various stages self.small = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3) self.motion = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3) self.eye = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3) self.mhi = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_32F, 1) self.orient = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_32F, 1) self.segmask = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_32F, 1) self.mask = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1) self.temp = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3) self.buf = range(10) for i in range(self.n_frames): self.buf[i] = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1) cv.SetZero(self.buf[i]) self.combined = cv.CreateImage( (self.smallwidth * self.xwindows, self.smallheight), cv.IPL_DEPTH_8U, 3) if self.store: self.writer = cv.CreateVideoWriter(self.output, 0, 15, cv.GetSize(self.combined), 1) # make window cv.NamedWindow("Motion Detection") cv.CreateTrackbar('Height', 'Motion Detection', self.height_value, 100, self.change_height) cv.CreateTrackbar('Jitter', 'Motion Detection', self.jitter_value, 100, self.change_jitter)
def __init__(self, imagem): self.imagem = imagem self.raio = 0 cv.NamedWindow("Transformada de Fourier", 1) cv.NamedWindow("Inversa da Fourier", 1) cv.CreateTrackbar("Filtro passa baixa", "Transformada de Fourier", self.raio, 50, self.atualiza_versao) self.atualiza_foto()
def main(): global thresh1, thresh2 capture = cv.CaptureFromCAM(0) cv.NamedWindow("capture") cv.NamedWindow("Segmentation") cv.CreateTrackbar("thresh2", "Segmentation", thresh2, 255, on_trackbar2) cv.CreateTrackbar("thresh1", "Segmentation", thresh1, 255, on_trackbar) storage = cv.CreateMemStorage(0) frameAux = cv.QueryFrame(capture) segmented = cv.CreateImage(cv.GetSize(frameAux), 8, 3) while (True): frame = cv.QueryFrame(capture) cv.ShowImage("capture", frame) # cv.PyrMeanShiftFiltering(frame, segmented, 100, 50) print thresh1, thresh2 cv.PyrSegmentation(frame, segmented, storage, 3, thresh1, thresh2) cv.ShowImage("Segmentation", segmented) cv.WaitKey(100)
def get_lines(self, image_name, MIN_X, MAX_X, MIN_Y, MAX_Y): cv.NamedWindow('Output', cv.CV_WINDOW_NORMAL) self.__plotw = MAX_X - MIN_X self.__ploth = MAX_Y - MIN_Y self.__load_image(image_name) cv.CreateTrackbar('width', 'Output', self.__nwidth, self.__gray.cols, self.__width_callback) cv.CreateTrackbar('gamma', 'Output', 220, 400, self.__gamma_callback) self.__width_callback(self.__nwidth) key = cv.WaitKey() while not (key == ord('q') or key == ord('e')): key = cv.WaitKey() print key if key == ord('e'): sys.exit(0) return self.__points
def gui(): cv.NamedWindow("Window") def drag(x): print x cv.CreateTrackbar("track1", "Window", 0, 100, drag) img = normalize_rgb(cv.LoadImage("sample/0003_00000002.jpg")) cv.ShowImage("Window", img) cv.WaitKey(0)
def calibrate_screen(self): # in case something else is still open cv.DestroyAllWindows() capture = cv.CaptureFromCAM(self.camera_index) if not capture: QMessageBox.information(self, "Camera Error", "Camera not found") return cv.NamedWindow("hold up object at preferred distance from camera", cv.CV_WINDOW_AUTOSIZE) cv.NamedWindow("select for max visibility", cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow("hold up object at preferred distance from camera", 320, 0) cv.MoveWindow("select for max visibility", 800, 82) cv.CreateTrackbar("Start at color", "hold up object at preferred distance from camera", self.low_color, 179, self.update_low_color) cv.CreateTrackbar("End at color", "hold up object at preferred distance from camera", self.high_color, 179, self.update_high_color) camera_on = True while camera_on: if (not self.busy_updating): frame = cv.QueryFrame(capture) if not frame: break # convert color to hue space for easier tracking imgHSV = cv.CreateImage(cv.GetSize(frame), 8, 3) cv.CvtColor(frame, imgHSV, cv.CV_BGR2HSV) imgThresh = cv.CreateImage(cv.GetSize(frame), 8, 1) # interactive thresholding cv.InRangeS(imgHSV, cv.Scalar(self.low_color, self.MED_SV, self.MED_SV), cv.Scalar(self.high_color, self.MAX_SV, self.MAX_SV), imgThresh) moments = cv.Moments(cv.GetMat(imgThresh)) self.calibration_area = cv.GetCentralMoment(moments, 0, 0) # shrink images for display small_thresh = cv.CreateImage((self.fit_camera_width, self.fit_camera_height), 8, 1) cv.Resize(imgThresh, small_thresh) small_frame = cv.CreateImage((self.fit_camera_width, self.fit_camera_height), 8, 3) cv.Resize(frame, small_frame) cv.ShowImage("hold up object at preferred distance from camera", small_frame) cv.ShowImage("select for max visibility", small_thresh) k = cv.WaitKey(1) # press q or escape to quit camera view if k == 27 or k == 113 or self.end_record: camera_on = False cv.DestroyAllWindows() self.end_record = False break
def __init__(self, *args): CalibrationNode.__init__(self, *args) cv.NamedWindow("display") self.font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.20, 1, thickness=2) #self.button = cv.LoadImage("%s/button.jpg" % roslib.packages.get_pkg_dir(PKG)) cv.SetMouseCallback("display", self.on_mouse) cv.CreateTrackbar("scale", "display", 0, 100, self.on_scale)
def __init__(self, imagem_fonte): self.imagem_fonte = imagem_fonte self.imagem_destino = cv.CloneMat(imagem_fonte) self.imagemHistograma = cv.CreateImage((512, 100), 8, 1) self.histograma = cv.CreateHist([512], cv.CV_HIST_ARRAY, [[0, 256]], 1) self.brilho = 0 self.contraste = 0 cv.NamedWindow("Foto Tons Cinza", 1) cv.NamedWindow("Foto Equalizada", 1) cv.NamedWindow("Histograma Equalizado", 1) cv.CreateTrackbar("Brilho", "Histograma Equalizado", 100, 200, self.atualiza_brilho) cv.CreateTrackbar("Contraste", "Histograma Equalizado", 100, 200, self.atualiza_contraste) self.atualiza_brilhocontraste()
def get_polygons(self, image_name, newX, MIN_X, MAX_X, MIN_Y, MAX_Y): cv.NamedWindow('Canny', cv.CV_WINDOW_NORMAL) cv.NamedWindow('Contours', cv.CV_WINDOW_NORMAL) cv.CreateTrackbar('smooth', 'Canny', self.__smooth_val, 10, self.__smooth_val_callback) cv.CreateTrackbar('apeture', 'Canny', self.__canny_apeture, 2, self.__canny_apeture_callback) cv.CreateTrackbar('lowThreshold', 'Canny', self.__canny_lo, 100, self.__canny_lo_callback) cv.CreateTrackbar('highThreshold', 'Canny', self.__canny_hi, 100, self.__canny_hi_callback) cv.CreateTrackbar('poly acc', 'Contours', self.__poly_acc, 1000, self.__poly_acc_callback) self.__load_image(image_name, newX) self.__smooth_val_callback(self.__smooth_val) key = cv.WaitKey() while not (key == ord('q') or key == ord('e')): key = cv.WaitKey() print key if key == ord('e'): sys.exit(0) return self.__prep_for_machine(MIN_X, MAX_X, MIN_Y, MAX_Y)
def atch_trackbars_to_win(name, color): mode = color.get_mode() if mode == ColorSpace.HSV: v1 = 'H' v2 = 'S' v3 = 'V' mx_1 = ColorSpace.MAX_HUE elif mode == ColorSpace.RGB: v1 = 'R' v2 = 'G' v3 = 'B' mx_1 = ColorSpace.MAX_RGB i = 'mi ' x = 'mx ' mx_2 = ColorSpace.MAX_SAT mx_3 = ColorSpace.MAX_VAL cv.CreateTrackbar(i + v1, name, color.mn_1_ or 0, mx_1, color.set_mn_1) cv.CreateTrackbar(i + v2, name, color.mn_1_ or 0, mx_2, color.set_mn_2) cv.CreateTrackbar(i + v3, name, color.mn_1_ or 0, mx_3, color.set_mn_3) cv.CreateTrackbar(x + v1, name, color.mx_1_ or mx_1, mx_1, color.set_mx_1) cv.CreateTrackbar(x + v2, name, color.mx_2_ or mx_2, mx_2, color.set_mx_2) cv.CreateTrackbar(x + v3, name, color.mx_3_ or mx_3, mx_2, color.set_mx_3)
def create_trackbar(self, var, max=255): """ Function to create trackbar for a variable. Arguments: var - The variable name to create a trackbar for. The variable name must be already defined as self.<variable name> and initialized to some value. max - The maximum value the trackbar can slide to. Min is always zero. """ cv.CreateTrackbar("%s" % var, self.name, getattr(self, var), max, lambda value: setattr(self, var, value))
def createTrackbar(self, name, val=0, maxval=255, callback=None): """Insert a new Trackbar""" if callback is None: def callback(name, a): pass def wrapper(a): self.handleTrackbarEvent(name, a) callback(name, a) cv.CreateTrackbar(name, self.name, val, maxval, wrapper) wrapper(val)
def setWindows(): cv.NamedWindow("Image") cv.CreateTrackbar("LowerH", "Image", lowerH, 180, None) cv.CreateTrackbar("UpperH", "Image", upperH, 180, None) cv.CreateTrackbar("LowerS", "Image", lowerS, 256, None) cv.CreateTrackbar("UpperS", "Image", upperS, 256, None) cv.CreateTrackbar("LowerV", "Image", lowerV, 256, None) cv.CreateTrackbar("UpperV", "Image", upperV, 256, None)
def initialize_gui(self): """Initializes GUI: - Windows for incoming images from left camera and right camera - Windows for thresholded image from left camera and right camera - Control window containing threshold sliders and threshold auto-select buttons. """ # Instantiate OpenCV windows for displaying incoming images cv.NamedWindow('Left Camera', 1) cv.MoveWindow('Left Camera', 0, 0) #cv.NamedWindow('Right Camera', 2) #cv.MoveWindow('Right Camera', 760, 0) # Set callback for mouse input to Left Camera window # Used to select regions of interest for target thresholding cv.SetMouseCallback('Left Camera', self.handle_mouse_left_camera, None) # Instantiate OpenCV windows for displaying thresholded image cv.NamedWindow('Left Threshold', 3) cv.MoveWindow('Left Threshold', 0, 480) #cv.NamedWindow('Right Threshold', 4) #cv.MoveWindow('Right Threshold', 760, 480) # Instantiate controls window cv.NamedWindow('Threshold Controls', 5) cv.MoveWindow('Threshold Controls', 760, 540) # Create sliders for tuning RGB thresholds cv.CreateTrackbar('low_hue', 'Threshold Controls', self.low_thresholds['hue'], 179, lambda x: self.change_slider('low', 'hue', x)) cv.CreateTrackbar('high_hue', 'Threshold Controls', self.high_thresholds['hue'], 179, lambda x: self.change_slider('high', 'hue', x)) cv.CreateTrackbar('low_sat', 'Threshold Controls', self.low_thresholds['sat'], 255, lambda x: self.change_slider('low', 'sat', x)) cv.CreateTrackbar('high_sat', 'Threshold Controls', self.high_thresholds['sat'], 255, lambda x: self.change_slider('high', 'sat', x)) cv.CreateTrackbar('low_val', 'Threshold Controls', self.low_thresholds['val'], 255, lambda x: self.change_slider('low', 'val', x)) cv.CreateTrackbar('high_val', 'Threshold Controls', self.high_thresholds['val'], 255, lambda x: self.change_slider('high', 'val', x))
def createTrackbars(window): def set1a(x): T[1][0]=x def set2a(x): T[1][1]=x def set3a(x): T[1][2]=x def set1z(x): T[2][0]=x def set2z(x): T[2][1]=x def set3z(x): T[2][2]=x global trackbar_window trackbar_window = window cv.CreateTrackbar("ch1 min", window, T[1][0], 255, set1a) cv.CreateTrackbar("ch2 min", window, T[1][1], 255, set2a) cv.CreateTrackbar("ch3 min", window, T[1][2], 255, set3a) cv.CreateTrackbar("ch1 max", window, T[2][0], 255, set1z) cv.CreateTrackbar("ch2 max", window, T[2][1], 255, set2z) cv.CreateTrackbar("ch3 max", window, T[2][2], 255, set3z)
def __init__(self): self.initConst() self.initCamVideo() self.setRef() #~ //~ Inicjuje okna do ogladania cv.namedWindow("original", 0) #~ cv.namedWindow("threshold",0) cv.namedWindow("edge", 0) # display orig image flag, self.img = self.cap.read() if flag == False: while (1): flag, self.img = self.cap.read() time.sleep(0.33) #~ cv.imshow("original", self.img) # convert to gray and alter bits self.gray = cv.cvtColor(self.img, cv.COLOR_BGR2GRAY) #~ cv.bitwise_not(self.gray, self.gray) # shape of images print "shape: ", self.gray.shape self.rows, self.cols = self.gray.shape self.roi[2] = self.cols self.roi[3] = self.rows # Create trackbar and init default values self.switch_callback(self._threshold) CV.CreateTrackbar("THRESHOLD", "original", self._threshold, 255, self.switch_callback) #~ cv.createTrackbar( "RadiusMin", "original", _minRad, 10, self.switch_callback ) # Set mouse events on cv.setMouseCallback("original", self.onMouse, 0)