Python cv2.setTrackbarPos() Examples

The following are 16 code examples of cv2.setTrackbarPos(). 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: main.py    From OpenLabeling with Apache License 2.0 6 votes vote down vote up
def set_selected_bbox(set_class):
    global is_bbox_selected, selected_bbox
    smallest_area = -1
    # if clicked inside multiple bboxes selects the smallest one
    for idx, obj in enumerate(img_objects):
        ind, x1, y1, x2, y2 = obj
        x1 = x1 - dragBBox.sRA
        y1 = y1 - dragBBox.sRA
        x2 = x2 + dragBBox.sRA
        y2 = y2 + dragBBox.sRA
        if pointInRect(mouse_x, mouse_y, x1, y1, x2, y2):
            is_bbox_selected = True
            tmp_area = get_bbox_area(x1, y1, x2, y2)
            if tmp_area < smallest_area or smallest_area == -1:
                smallest_area = tmp_area
                selected_bbox = idx
                if set_class:
                    # set class to the one of the selected bounding box
                    cv2.setTrackbarPos(TRACKBAR_CLASS, WINDOW_NAME, ind) 
Example #2
Source File: InRange.py    From Advanced_Lane_Lines with MIT License 5 votes vote down vote up
def on_low_H_thresh_trackbar(val):
	global low_H
	global high_H
	low_H = val
	low_H = min(high_H-1, low_H)
	cv.setTrackbarPos(low_H_name, window_detection_name, low_H) 
Example #3
Source File: InRange.py    From Advanced_Lane_Lines with MIT License 5 votes vote down vote up
def on_high_H_thresh_trackbar(val):
	global low_H
	global high_H
	high_H = val
	high_H = max(high_H, low_H+1)
	cv.setTrackbarPos(high_H_name, window_detection_name, high_H) 
Example #4
Source File: InRange.py    From Advanced_Lane_Lines with MIT License 5 votes vote down vote up
def on_low_S_thresh_trackbar(val):
	global low_S 
	global high_S
	low_S = val
	low_S = min(high_S - 1, low_S)
	cv.setTrackbarPos(low_S_name, window_detection_name, low_S) 
Example #5
Source File: InRange.py    From Advanced_Lane_Lines with MIT License 5 votes vote down vote up
def on_high_S_thresh_trackbar(val):
	global low_S
	global high_S
	high_S = val
	high_S = max(high_S, low_S+1)
	cv.setTrackbarPos(high_S_name, window_detection_name, high_S) 
Example #6
Source File: InRange.py    From Advanced_Lane_Lines with MIT License 5 votes vote down vote up
def on_low_V_thresh_trackbar(val):
	global low_V 
	global high_V
	low_V = val
	low_V = min(high_V-1, low_V)
	cv.setTrackbarPos(low_V_name, window_detection_name, low_V) 
Example #7
Source File: auto_marker.py    From lightnet with MIT License 5 votes vote down vote up
def update_image(image_id, category_id = 0, image_filenames=[], enable_vis=True, enable_marker_dump=False):
    try:
        global contours, hierarchy, img, gray, g_image_filenames
        if len(image_filenames) > 0:
            g_image_filenames=image_filenames
        img=cv.imread(g_image_filenames[image_id])
        # print(g_image_filenames[image_id])
        cv.setTrackbarPos('image', 'marker', image_id)

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        gray[np.where(gray <= [3])] = [187]
        gray = cv.medianBlur(gray, 11)

        if enable_vis:
            cv.imshow('gray', gray)

        if CANNY_MODE:
            thrs1 = cv.getTrackbarPos('thrs1', 'marker')
            thrs2 = cv.getTrackbarPos('thrs2', 'marker')
            bin = cv.Canny(gray, thrs1, thrs2, apertureSize=5)
        else:
            bin = cv.adaptiveThreshold(
                gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 31, 10)

        if enable_vis:
            cv.imshow('bin', bin)

        _, contours0, hierarchy = cv.findContours(
            bin.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
        contours = [cnt for cnt in contours0 if cv.contourArea(cnt) > 200]

        if enable_vis:
            cv.imshow('image', img)
        update_contour(category_id, image_id, enable_vis, enable_marker_dump)
    except Exception:
        import traceback
        traceback.print_exc()
        raise 
Example #8
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def on_low_H_thresh_trackbar(self, val):
        self.low_H = val
        self.low_H = min(self.high_H-1, self.low_H)
        cv2.setTrackbarPos(self.low_H_name, self.window_name, self.low_H) 
Example #9
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def on_high_H_thresh_trackbar(self, val):
        self.high_H = val
        self.high_H = max(self.high_H, self.low_H+1)
        cv2.setTrackbarPos(self.high_H_name, self.window_name, self.high_H) 
Example #10
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def on_low_S_thresh_trackbar(self, val):
        self.low_S = val
        self.low_S = min(self.high_S-1, self.low_S)
        cv2.setTrackbarPos(self.low_S_name, self.window_name, self.low_S) 
Example #11
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def on_high_S_thresh_trackbar(self, val):
        self.high_S = val
        self.high_S = max(self.high_S, self.low_S+1)
        cv2.setTrackbarPos(self.high_S_name, self.window_name, self.high_S) 
Example #12
Source File: thresholding.py    From smashscan with MIT License 5 votes vote down vote up
def on_low_V_thresh_trackbar(self, val):
        self.low_V = val
        self.low_V = min(self.high_V-1, self.low_V)
        cv2.setTrackbarPos(self.low_V_name, self.window_name, self.low_V) 
Example #13
Source File: trackbar.py    From PyIntroduction with MIT License 5 votes vote down vote up
def setValue(self, value):
        cv2.setTrackbarPos(self._param_name, self._win_name, value) 
Example #14
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 #15
Source File: main_auto.py    From OpenLabeling with Apache License 2.0 4 votes vote down vote up
def init_trackers(self, bboxes, classIds, json_file_data,json_file_path, img_path):
        global img_index

        anchor_id = json_file_data['n_anchor_ids']
        frame_data_dict = json_file_data['frame_data_dict']
        image = cv2.imread(img_path)
        for box, classId in zip(bboxes, classIds):
            # Init trackers with those classId and anchorId
            anchor_id = anchor_id + 1
            tracker = Tracker(self.tracker_type, anchorId=anchor_id, classId=classId)
            initial_bbox = (box[0], box[1], box[2], box[3])
            tracker.instance.init(self.init_frame, initial_bbox)
            self.trackers.append(tracker)

            # Initialize trackers on json files.
            pred_counter  = 0
            xmin, ymin, w, h = map(int, box)
            xmax = xmin + w
            ymax = ymin + h
            obj = [int(classId), xmin, ymin, xmax, ymax]
            frame_data_dict = json_file_add_object(frame_data_dict, img_path, anchor_id, pred_counter, obj)

            # Save prediction
            annotation_paths = get_annotation_paths(img_path, annotation_formats)
            save_bounding_box(annotation_paths, int(classId), (xmin, ymin), (xmax, ymax), self.img_w, self.img_h)



            #Draw
            color = class_rgb[int(tracker.classId)].tolist()
            cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, LINE_THICKNESS)

        img_index = increase_index(img_index, last_img_index)
        cv2.setTrackbarPos(TRACKBAR_IMG, WINDOW_NAME, img_index)
        cv2.imshow(WINDOW_NAME, image)
        pressed_key = cv2.waitKey(DELAY)

        json_file_data.update({'n_anchor_ids': (anchor_id + 1)})

        # save the updated data
        with open(json_file_path, 'w') as outfile:
            json.dump(json_file_data, outfile, sort_keys=True, indent=4) 
Example #16
Source File: main_auto.py    From OpenLabeling with Apache License 2.0 4 votes vote down vote up
def predict_next_frames(self,json_file_data,json_file_path):
        global img_index

        anchor_id = json_file_data['n_anchor_ids']
        frame_data_dict = json_file_data['frame_data_dict']

        pred_counter = 0
        for frame_path in self.next_frame_path_list:
            is_there_missed_tracker = False
            bboxes = []
            # Check if there is any "miss" tracker
            for tracker in self.trackers:
                next_image = cv2.imread(frame_path)
                success, bbox = tracker.instance.update(next_image.copy())
                bboxes.append(bbox)
                if not success:
                    is_there_missed_tracker = True
                    break

            # if there is no "miss" tracker, then save labelled objects into files and keep predict at the next frame
            if not is_there_missed_tracker:
                pred_counter += 1
                for i, tracker in enumerate(self.trackers):
                    box = bboxes[i]

                    xmin, ymin, w, h = map(int, box)
                    xmax = xmin + w
                    ymax = ymin + h
                    obj = [int(tracker.classId), xmin, ymin, xmax, ymax]
                    frame_data_dict = json_file_add_object(frame_data_dict, frame_path, int(tracker.anchorId), pred_counter, obj)

                    color = class_rgb[int(tracker.classId)].tolist()
                    cv2.rectangle(next_image, (xmin, ymin), (xmax, ymax), color, LINE_THICKNESS)

                    # save prediction
                    annotation_paths = get_annotation_paths(frame_path, annotation_formats)
                    save_bounding_box(annotation_paths, int(tracker.classId), (xmin, ymin), (xmax, ymax), self.img_w, self.img_h)



                cv2.imshow(WINDOW_NAME, next_image)
                pressed_key = cv2.waitKey(DELAY)

                img_index = increase_index(img_index, last_img_index)

                cv2.setTrackbarPos(TRACKBAR_IMG, WINDOW_NAME, img_index)
            # If there is "miss" traker, then break Tracker Manager.
            # Note:Ready to use "Object Detection" to detect object
            else:
                break

        json_file_data.update({'n_anchor_ids': (anchor_id + 1)})
        # save the updated data
        with open(json_file_path, 'w') as outfile:
            json.dump(json_file_data, outfile, sort_keys=True, indent=4)




# change to the directory of this script