本文整理匯總了Python中cv2.setTrackbarPos方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.setTrackbarPos方法的具體用法?Python cv2.setTrackbarPos怎麽用?Python cv2.setTrackbarPos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.setTrackbarPos方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_selected_bbox
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例2: on_low_H_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例3: on_high_H_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例4: on_low_S_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例5: on_high_S_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例6: on_low_V_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例7: update_image
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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
示例8: on_low_H_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例9: on_high_H_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例10: on_low_S_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例11: on_high_S_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例12: on_low_V_thresh_trackbar
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)
示例13: setValue
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
def setValue(self, value):
cv2.setTrackbarPos(self._param_name, self._win_name, value)
示例14: preview
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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()
示例15: init_trackers
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setTrackbarPos [as 別名]
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)