Python cv2.createTrackbar() Examples

The following are 28 code examples of cv2.createTrackbar(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: ColorPalette.py    From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License 7 votes vote down vote up
def main():
    windowName = "OpenCV BGR Color Palette"
    imageData = np.zeros((512, 512, 3), np.uint8)

    cv2.namedWindow(windowName)

    cv2.createTrackbar('Blue', windowName, 0, 255, passFunction)
    cv2.createTrackbar('Green', windowName, 0, 255, passFunction)
    cv2.createTrackbar('Red', windowName, 0, 255, passFunction)

    while (True):
        cv2.imshow(windowName, imageData)

        if cv2.waitKey(1) & 0xFF == 27:
            break

        blue = cv2.getTrackbarPos('Blue', windowName)
        green = cv2.getTrackbarPos('Green', windowName)
        red = cv2.getTrackbarPos('Red', windowName)

        imageData[:] = [blue, green, red]
        print(blue, green, red)

    cv2.destroyWindow(windowName) 
Example #2
Source File: __init__.py    From colorfilters with MIT License 7 votes vote down vote up
def _initialize_window(self):
        """Creates the window."""
        cv.namedWindow(self.name)
        for i, (chname, min_, max_) in enumerate(
            zip(self.channel_names, self.channel_mins, self.channel_maxes)
        ):
            cv.createTrackbar(
                chname + MIN_SUFFIX,
                self.name,
                min_,
                max_,
                partial(self._update_lowerb, i),
            )
            cv.setTrackbarMin(chname + MIN_SUFFIX, self.name, min_)
            cv.createTrackbar(
                chname + MAX_SUFFIX,
                self.name,
                max_,
                max_,
                partial(self._update_upperb, i),
            )
        self._update() 
Example #3
Source File: Transition.py    From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def main():
    windowName = "Transition Effect"

    cv2.namedWindow("Transition Effect")

    imageOne = cv2.imread("../data/lena_color_512.tif", 1)
    imageTwo = cv2.imread("../data/mandril_color.tif", 1)

    cv2.createTrackbar("Alpha", windowName, 0, 1000, passFunction)

    while True:

        alpha = cv2.getTrackbarPos("Alpha", windowName) / 1000
        beta = 1 - alpha

        output = cv2.addWeighted(imageOne, alpha, imageTwo, beta, 0)

        cv2.imshow(windowName, output)

        if cv2.waitKey(1) & 0xFF == 27:
            break

    cv2.destroyAllWindows() 
Example #4
Source File: MediaPlayer.py    From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def main():
    windowname = "OpenCV Media Player"
    cv2.namedWindow(windowname)

    videoFilePath = "/media/amarpandey/Media Files/Movies/Game Of Thrones/Season Seven/Game.of.Thrones.S07E03.720p.WEB.h264-TBS[eztv].mkv"

    capture = cv2.VideoCapture(videoFilePath)
    cv2.createTrackbar('FrameSpeed', windowname, 10, 600, passFunction)

    while (capture.isOpened()):

        FrameSpeed = cv2.getTrackbarPos('FrameSpeed', windowname)
        flag, frame = capture.read()

        if FrameSpeed <= 0: FrameSpeed = 1

        if flag:
            cv2.imshow(windowname, frame)
            if cv2.waitKey(FrameSpeed) & 0xFF == 27:  # because 33 * FPS == 1 second
                break
        else:
            break

    cv2.destroyWindow(windowname)
    capture.release() 
Example #5
Source File: Tshirt.py    From virtual-dressing-room with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        self.norm_rgb=np.zeros((config.height,config.width,3),np.uint8)
        self.dst=np.zeros((config.height,config.width),np.uint8)
        self.b=0
        self.g=0
        self.r=0
        
        self.lb=0
        self.lg=0
        self.lr=0
        
        self.m=np.zeros((config.height,config.width),np.uint8)
        #self.win=cv2.namedWindow("detect")
        #self.dst=cv.CreateImage((config.width,config.height),8,1)
        
        #cv2.createTrackbar("blue", "detect",0,255,self.change_b)
        #cv2.createTrackbar("green","detect",0,255,self.change_g)
        #cv2.createTrackbar("red","detect",0,255,self.change_r)
        
        #cv2.createTrackbar("low_blue", "detect",0,255,self.change_lb)
        #cv2.createTrackbar("low_green","detect",0,255,self.change_lg)
        #cv2.createTrackbar("low_red","detect",0,255,self.change_lr) 
Example #6
Source File: enjoy_latent.py    From srl-zoo with MIT License 6 votes vote down vote up
def createFigureAndSlider(name, state_dim):
    """
    Creating a window for the latent space visualization, an another for the slider to control it
    :param name: name of model (str)
    :param state_dim: (int)
    :return:
    """
    # opencv gui setup
    cv2.namedWindow(name, cv2.WINDOW_NORMAL)
    cv2.resizeWindow(name, 500, 500)
    cv2.namedWindow('slider for ' + name)
    # add a slider for each component of the latent space
    for i in range(state_dim):
        # the sliders MUST be between 0 and max, so we placed max at 100, and start at 50
        # So that when we substract 50 and divide 10 we get [-5,5] for each component
        cv2.createTrackbar(str(i), 'slider for ' + name, 50, 100, (lambda a: None)) 
Example #7
Source File: guiutils.py    From opencv-gui-helper-tool with MIT License 5 votes vote down vote up
def __init__(self, image, filter_size=1, threshold1=0, threshold2=0):
        self.image = image
        self._filter_size = filter_size
        self._threshold1 = threshold1
        self._threshold2 = threshold2

        def onchangeThreshold1(pos):
            self._threshold1 = pos
            self._render()

        def onchangeThreshold2(pos):
            self._threshold2 = pos
            self._render()

        def onchangeFilterSize(pos):
            self._filter_size = pos
            self._filter_size += (self._filter_size + 1) % 2
            self._render()

        cv2.namedWindow('edges')

        cv2.createTrackbar('threshold1', 'edges', self._threshold1, 255, onchangeThreshold1)
        cv2.createTrackbar('threshold2', 'edges', self._threshold2, 255, onchangeThreshold2)
        cv2.createTrackbar('filter_size', 'edges', self._filter_size, 20, onchangeFilterSize)

        self._render()

        print "Adjust the parameters as desired.  Hit any key to close."

        cv2.waitKey(0)

        cv2.destroyWindow('edges')
        cv2.destroyWindow('smoothed') 
Example #8
Source File: ui_utils.py    From StereoVision with GNU General Public License v3.0 5 votes vote down vote up
def _initialize_trackbars(self):
        """
        Initialize trackbars by discovering ``block_matcher``'s parameters.
        """
        for parameter in self.block_matcher.parameter_maxima.keys():
            maximum = self.block_matcher.parameter_maxima[parameter]
            if not maximum:
                maximum = self.shortest_dimension
            cv2.createTrackbar(parameter, self.window_name,
                               self.block_matcher.__getattribute__(parameter),
                               maximum,
                               partial(self._set_value, parameter)) 
Example #9
Source File: ImageManipulation.py    From ImageProcessingProjects with MIT License 5 votes vote down vote up
def thresholdGrayImage():
    cv.namedWindow('Thresholding', cv.WINDOW_AUTOSIZE)
    cv.createTrackbar('Threshold', 'Thresholding',128, 255, sliderCallBack)
    cv.waitKey(0) 
Example #10
Source File: __init__.py    From magicwand with MIT License 5 votes vote down vote up
def __init__(self, img, name="Magic Wand Selector", connectivity=4, tolerance=32):
        self.name = name
        h, w = img.shape[:2]
        self.img = img
        self.mask = np.zeros((h, w), dtype=np.uint8)
        self._flood_mask = np.zeros((h + 2, w + 2), dtype=np.uint8)
        self._flood_fill_flags = (
            connectivity | cv.FLOODFILL_FIXED_RANGE | cv.FLOODFILL_MASK_ONLY | 255 << 8
        )  # 255 << 8 tells to fill with the value 255
        cv.namedWindow(self.name)
        self.tolerance = (tolerance,) * 3
        cv.createTrackbar(
            "Tolerance", self.name, tolerance, 255, self._trackbar_callback
        )
        cv.setMouseCallback(self.name, self._mouse_callback) 
Example #11
Source File: webcam.py    From WCT-TF with MIT License 5 votes vote down vote up
def __init__(self, style_path, img_size=512, crop_size=512, scale=1, alpha=1, swap5=False, ss_alpha=1, passes=1):
        if os.path.isdir(style_path):
            self.style_imgs = get_files(style_path)
        else:
            self.style_imgs = [style_path]  # Single image instead of folder

        self.style_rgb = None

        self.img_size = img_size
        self.crop_size = crop_size
        self.scale = scale
        self.alpha = alpha
        self.ss_alpha = ss_alpha
        self.passes = passes

        cv2.namedWindow('Style Controls')
        if len(self.style_imgs) > 1:
            # Select style image by index
            cv2.createTrackbar('Index','Style Controls', 0, len(self.style_imgs)-1, self.set_idx)
        
        # Blend param for WCT/AdaIN transform
        cv2.createTrackbar('WCT/AdaIN alpha','Style Controls', int(self.alpha*100), 100, self.set_alpha)

        # Separate blend setting for style-swap
        cv2.createTrackbar('Style-swap alpha','Style Controls', int(self.ss_alpha*100), 100, self.set_ss_alpha)

        # Resize style to this size before cropping
        cv2.createTrackbar('Style size','Style Controls', self.img_size, 1280, self.set_size)

        # Size of square crop box for style
        cv2.createTrackbar('Style crop','Style Controls', self.crop_size, 1280, self.set_crop_size)

        # Scale the content before processing
        cv2.createTrackbar('Content scale','Style Controls', int(self.scale*100), 200, self.set_scale)

        # Num times to repeat the stylization pipeline
        cv2.createTrackbar('# of passes','Style Controls', self.passes, 5, self.set_passes)

        self.set_style(random=True, window='Style Controls') 
Example #12
Source File: visual_hsv_bounds.py    From robot-camera-platform with GNU General Public License v3.0 5 votes vote down vote up
def setup_trackbars(range_filter):
    cv2.namedWindow("Trackbars", 0)
    for i in ["MIN", "MAX"]:
        v = 0 if i == "MIN" else 255
        for j in range_filter:
            cv2.createTrackbar("%s_%s" % (j, i), "Trackbars", v, 255, lambda: None) 
Example #13
Source File: range_detector.py    From ImageAnalysis with MIT License 5 votes vote down vote up
def setup_trackbars(range_filter):
    cv2.namedWindow("Trackbars", 0)

    for i in ["MIN", "MAX"]:
        v = 0 if i == "MIN" else 255

        for j in range_filter:
            cv2.createTrackbar("%s_%s" % (j, i), "Trackbars", v, 255, callback) 
Example #14
Source File: range_detector-rg.py    From ImageAnalysis with MIT License 5 votes vote down vote up
def setup_trackbars(range_filter):
    cv2.namedWindow("Trackbars", 0)

    for i in ["MIN", "MAX"]:
        v = 0 if i == "MIN" else 255

        for j in range_filter:
            cv2.createTrackbar("%s_%s" % (j, i), "Trackbars", v, 255, callback) 
Example #15
Source File: plane_ar.py    From PyCV-time with MIT License 5 votes vote down vote up
def __init__(self, src):
        self.cap = video.create_capture(src)
        self.frame = None
        self.paused = False
        self.tracker = PlaneTracker()

        cv2.namedWindow('plane')
        cv2.createTrackbar('focal', 'plane', 25, 50, common.nothing)
        self.rect_sel = common.RectSelector('plane', self.on_rect) 
Example #16
Source File: plane_ar.py    From PyCV-time with MIT License 5 votes vote down vote up
def __init__(self, src):
        self.cap = video.create_capture(src)
        self.frame = None
        self.paused = False
        self.tracker = PlaneTracker()

        cv2.namedWindow('plane')
        cv2.createTrackbar('focal', 'plane', 25, 50, common.nothing)
        self.rect_sel = common.RectSelector('plane', self.on_rect) 
Example #17
Source File: plane_ar.py    From OpenCV-Python-Tutorial with MIT License 5 votes vote down vote up
def __init__(self, src):
        self.cap = video.create_capture(src, presets['book'])
        self.frame = None
        self.paused = False
        self.tracker = PlaneTracker()

        cv2.namedWindow('plane')
        cv2.createTrackbar('focal', 'plane', 25, 50, common.nothing)
        self.rect_sel = common.RectSelector('plane', self.on_rect) 
Example #18
Source File: color_replace.py    From virtual-dressing-room with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        global color
        self.rgb=np.zeros((config.height,config.width,3),np.uint8)
        self.mask=np.zeros((config.height,config.width),np.uint8)
        self.hue_val=color
        self.scratch=np.zeros((config.height,config.width,3),np.uint8)
        
        #cv2.namedWindow("hue")
        #cv2.createTrackbar("hue", "hue",self.hue_val,255,self.change) 
Example #19
Source File: trackbar.py    From PyIntroduction with MIT License 5 votes vote down vote up
def __init__(self, param_name, win_name, param_min, param_max, update_func=doNothing):
        self._update_func = update_func
        self._trackbar = cv2.createTrackbar(param_name, win_name, param_min, param_max, self._callback)
        self._param_name = param_name
        self._win_name = win_name

    # Trackbarの値を参照 
Example #20
Source File: webcam.py    From AdaIN-TF with MIT License 5 votes vote down vote up
def __init__(self, style_path, img_size=512, scale=1, alpha=1, interpolate=False):
        self.style_imgs = get_files(style_path)

        # Create room for two styles for interpolation
        self.style_rgbs = [None, None]

        self.img_size = img_size
        self.crop_size = 256
        self.scale = scale
        self.alpha = alpha

        cv2.namedWindow('Style Controls')
        if len(self.style_imgs) > 1:
            # Select style image by index
            cv2.createTrackbar('index','Style Controls', 0, len(self.style_imgs)-1, self.set_idx)
        
        # Blend param for AdaIN transform
        cv2.createTrackbar('alpha','Style Controls', 100, 100, self.set_alpha)

        # Resize style to this size before cropping
        cv2.createTrackbar('size','Style Controls', img_size, 2048, self.set_size)

        # Size of square crop box for style
        cv2.createTrackbar('crop size','Style Controls', 256, 2048, self.set_crop_size)

        # Scale the content before processing
        cv2.createTrackbar('scale','Style Controls', int(scale*100), 200, self.set_scale)

        self.set_style(random=True, window='Style Controls', style_idx=0)

        if interpolate:
            # Create a window to show second style image for interpolation
            cv2.namedWindow('style2')
            self.interp_weight = 1.
            cv2.createTrackbar('interpolation','Style Controls', 100, 100, self.set_interp)
            self.set_style(random=True, style_idx=1, window='style2') 
Example #21
Source File: color_range_detector.py    From Color-Tracker with MIT License 5 votes vote down vote up
def __init__(self, name, parent_window_name, init_value=0, max_value=255):
        self.parent_window_name = parent_window_name
        self.name = name
        self.init_value = init_value
        self.max_value = max_value

        cv2.createTrackbar(self.name, self.parent_window_name, self.init_value, self.max_value, lambda x: x) 
Example #22
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def __init__(self, video_location, start_fnum=0, stop_fnum=0):
        self.capture = cv2.VideoCapture(video_location)
        self.capture.set(cv2.CAP_PROP_POS_FRAMES, start_fnum)
        self.window_name = "Damage TM Parameter Analyzer"

        self.start_fnum = start_fnum
        self.stop_fnum = stop_fnum
        if stop_fnum == 0:
            self.stop_fnum = int(self.capture.get(cv2.CAP_PROP_FRAME_COUNT))

        cv2.namedWindow(self.window_name)
        cv2.createTrackbar("Step Size", self.window_name,
            1, 100, self.on_step_trackbar)
        cv2.createTrackbar("Delay", self.window_name,
            10, 500, self.on_delay_trackbar)
        cv2.createTrackbar("TM ~ Off, On", self.window_name,
            0, 1, self.on_tm_trackbar)

        self.step_size = 1
        self.step_delay = 10
        self.tm_flag = False

        # Read all ten of the damage integer images and extract a binary mask
        # based off of the alpha channel. Also, resize to a 360p height.
        self.orig_num_img, self.orig_num_mask = [None]*10, [None]*10
        self.num_img, self.num_mask = [None]*10, [None]*10
        for i in range(0, 10):
            self.orig_num_img[i], self.orig_num_mask[i] = util.get_image_and_mask(
                "resources/{:}.png".format(i), gray_flag=True)
            self.num_img[i] = util.resize_img(self.orig_num_img[i], 360/480)
            self.num_mask[i] = util.resize_img(self.orig_num_mask[i], 360/480)
        self.num_h, self.num_w = self.num_img[0].shape[:2]


    # The method that must be called to boot up the paramater analysis GUI. 
Example #23
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def __init__(self, video_location, start_fnum=0, stop_fnum=0):

        self.capture = cv2.VideoCapture(video_location)
        self.start_fnum = start_fnum
        self.stop_fnum = stop_fnum
        if stop_fnum == 0:
            self.stop_fnum = int(self.capture.get(cv2.CAP_PROP_FRAME_COUNT))

        self.window_name = 'Object Detection'
        self.low_H_name = 'Low H'
        self.low_S_name = 'Low S'
        self.low_V_name = 'Low V'
        self.high_H_name = 'High H'
        self.high_S_name = 'High S'
        self.high_V_name = 'High V'

        self.low_H, self.low_S, self.low_V = 0, 0, 0
        self.high_H, self.high_S, self.high_V = 180, 255, 255

        cv2.namedWindow(self.window_name)
        cv2.createTrackbar(self.low_H_name, self.window_name,
            self.low_H, 180, self.on_low_H_thresh_trackbar)
        cv2.createTrackbar(self.high_H_name, self.window_name,
            self.high_H, 180, self.on_high_H_thresh_trackbar)
        cv2.createTrackbar(self.low_S_name, self.window_name,
            self.low_S, 255, self.on_low_S_thresh_trackbar)
        cv2.createTrackbar(self.high_S_name, self.window_name,
            self.high_S, 255, self.on_high_S_thresh_trackbar)
        cv2.createTrackbar(self.low_V_name, self.window_name,
            self.low_V, 255, self.on_low_V_thresh_trackbar)
        cv2.createTrackbar(self.high_V_name, self.window_name,
            self.high_V, 255, self.on_high_V_thresh_trackbar)


    # The standard test iterates through the entire video with multiple track
    # bars to vary HSV thresholds. Results can be seen in a separate window. 
Example #24
Source File: auto_marker.py    From lightnet with MIT License 5 votes vote down vote up
def update_category(category_id):
    global g_image_filenames, g_category_id
    g_category_id = category_id
    g_image_filenames = glob.glob(category_folders[category_id] + '/*.jpg')
    cv.createTrackbar("image", 'marker', 0,
                      len(g_image_filenames) - 1, update_image)
    cv.setTrackbarMax('image', 'marker', len(g_image_filenames) - 1)
    update_image(0) 
Example #25
Source File: match_template.py    From OpenCV-Python-Tutorial with MIT License 5 votes vote down vote up
def main(argv):

   if (len(sys.argv) < 3):
      print 'Not enough parameters'
      print 'Usage:\nmatch_template_demo.py <image_name> <template_name> [<mask_name>]'
      return -1

   ## [load_image]
   global img
   global templ
   img = cv2.imread(sys.argv[1], cv2.IMREAD_COLOR)
   templ = cv2.imread(sys.argv[2], cv2.IMREAD_COLOR)

   if (len(sys.argv) > 3):
      global use_mask
      use_mask = True
      global mask
      mask = cv2.imread( sys.argv[3], cv2.IMREAD_COLOR )

   if ((img is None) or (templ is None) or (use_mask and (mask is None))):
      print 'Can\'t read one of the images'
      return -1
   ## [load_image]

   ## [create_windows]
   cv2.namedWindow( image_window, cv2.WINDOW_AUTOSIZE )
   cv2.namedWindow( result_window, cv2.WINDOW_AUTOSIZE )
   ## [create_windows]

   ## [create_trackbar]
   trackbar_label = 'Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED'
   cv2.createTrackbar( trackbar_label, image_window, match_method, max_Trackbar, MatchingMethod )
   ## [create_trackbar]

   MatchingMethod(match_method)

   ## [wait_key]
   cv2.waitKey(0)
   return 0
   ## [wait_key] 
Example #26
Source File: preview.py    From thingscoop with MIT License 4 votes vote down vote up
def preview(filename, classifier):
    cv2.namedWindow('video')

    duration = int(get_video_duration(filename))

    def trackbar_change(t):
        cap.set(cv2.cv.CV_CAP_PROP_POS_MSEC, t*1000)

    trackbar_prompt = 'Current position:'
    cv2.createTrackbar(trackbar_prompt, 'video', 0, duration, trackbar_change)

    cap = cv2.VideoCapture(filename)

    classification_result = None
    previous_time_in_seconds = None
    current_pos = 0

    tmp = tempfile.NamedTemporaryFile(suffix=".png")    
    
    while cap.isOpened():
        ret, frame = cap.read()

        cv2.imwrite(tmp.name, frame)

        if ret:
            current_pos = get_current_position(cap)

            if current_pos != previous_time_in_seconds:
                previous_time_in_seconds = current_pos
                classification_result = classifier.classify_image(tmp.name)
            
            if classification_result:
                add_text_to_frame(frame, format_classification(classification_result))

            cv2.imshow('video', frame)
        
        cv2.setTrackbarPos(trackbar_prompt, 'video', current_pos)
    
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break

    cap.release()
    cv2.destroyAllWindows() 
Example #27
Source File: colorthresh.py    From computer-vision with MIT License 4 votes vote down vote up
def __init__(self, mode="cam", source=0):
        self.PIXEL_MIN = 0
        self.PIXEL_MAX = 255
        self.BTN_HUE = 127

        self.CTRL_WIN = "Controls"
        self.THRESH_WIN = "Thresholded"
        self.IM_WIN = "Original"


        self.COLOR_SPACES = [key for key, code in
            ColorThreshold.CV_COLOR_CODES.items()]

        self.colorSpaceIdx = 0

        self.ch0LowVal = self.PIXEL_MIN
        self.ch0HighVal = self.PIXEL_MAX
        self.ch1LowVal = self.PIXEL_MIN
        self.ch1HighVal = self.PIXEL_MAX
        self.ch2LowVal = self.PIXEL_MIN
        self.ch2HighVal = self.PIXEL_MAX

        cv2.namedWindow(self.CTRL_WIN)
        cv2.namedWindow(self.THRESH_WIN)
        self.btn = self.BTN_HUE * np.ones((50, 400, 3), dtype=np.uint8)
        self.mode = mode
        self.source = source

        # Create trackbars.
        cv2.createTrackbar("Ch0 Low", self.CTRL_WIN, self.ch0LowVal,
            self.PIXEL_MAX, self.onTrackbar)
        cv2.createTrackbar("Ch0 High", self.CTRL_WIN, self.ch0HighVal,
            self.PIXEL_MAX, self.onTrackbar)
        cv2.createTrackbar("Ch1 Low", self.CTRL_WIN, self.ch1LowVal,
            self.PIXEL_MAX, self.onTrackbar)
        cv2.createTrackbar("Ch1 High", self.CTRL_WIN, self.ch1HighVal,
            self.PIXEL_MAX, self.onTrackbar)
        cv2.createTrackbar("Ch2 Low", self.CTRL_WIN, self.ch2LowVal,
            self.PIXEL_MAX, self.onTrackbar)
        cv2.createTrackbar("Ch2 High", self.CTRL_WIN, self.ch2HighVal,
            self.PIXEL_MAX, self.onTrackbar)

        # Link color space button to mouse event callback. Call
        # updateButton() to initialize button with color space text.
        cv2.setMouseCallback(self.CTRL_WIN, self.onMouse)
        self.updateButton() 
Example #28
Source File: thresholding.py    From smashscan with MIT License 4 votes vote down vote up
def __init__(self, video_location, start_fnum=0, stop_fnum=0):
        self.capture = cv2.VideoCapture(video_location)
        self.capture.set(cv2.CAP_PROP_POS_FRAMES, start_fnum)
        self.window_name = "Damage Parameter Analyzer"

        self.start_fnum = start_fnum
        self.stop_fnum = stop_fnum
        if stop_fnum == 0:
            self.stop_fnum = int(self.capture.get(cv2.CAP_PROP_FRAME_COUNT))

        cv2.namedWindow(self.window_name)
        cv2.createTrackbar("Step Size", self.window_name,
            1, 100, self.on_step_trackbar)
        cv2.createTrackbar("Delay", self.window_name,
            10, 500, self.on_delay_trackbar)
        cv2.createTrackbar("Thresh ~ Bin, Otsu", self.window_name,
            0, 1, self.on_thresh_trackbar)
        cv2.createTrackbar("Pre Blur ~ 0, Gaus, Med", self.window_name,
            0, 2, self.on_pre_blur_trackbar)
        cv2.createTrackbar("Post Blur ~ 0, Med", self.window_name,
            0, 1, self.on_post_blur_trackbar)
        cv2.createTrackbar("Contour Filter ~ Off, On", self.window_name,
            0, 1, self.on_contour_trackbar)
        cv2.createTrackbar("Contour Display ~ Off, On", self.window_name,
            0, 1, self.on_contour_disp_trackbar)
        cv2.createTrackbar("Contour Min Area", self.window_name,
            1, 1000, self.on_contour_min_area_trackbar)
        cv2.createTrackbar("Contour Max Area", self.window_name,
            5000, 5000, self.on_contour_max_area_trackbar)
        cv2.createTrackbar("OCR ~ Off, On", self.window_name,
            0, 1, self.on_ocr_trackbar)
        cv2.createTrackbar("OCR ~ 1 Line, 1 Word", self.window_name,
            0, 1, self.on_ocr_mode_trackbar)

        self.step_size = 1
        self.step_delay = 10
        self.pre_blur_val = 0
        self.thresh_flag = False
        self.post_blur_val = 0
        self.contour_flag = False
        self.contour_disp_flag = False
        self.contour_min_area = 1
        self.contour_max_area = 5000
        self.ocr_flag = False
        self.ocr_mode_flag = False


    # The method that must be called to boot up the paramater analysis GUI.