Python cv2.getTrackbarPos() Examples
The following are 30
code examples of cv2.getTrackbarPos().
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 |
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: fitline.py From PyCV-time with MIT License | 7 votes |
def update(_=None): noise = cv2.getTrackbarPos('noise', 'fit line') n = cv2.getTrackbarPos('point n', 'fit line') r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0 outn = int(n*r) p0, p1 = (90, 80), (w-90, h-80) img = np.zeros((h, w, 3), np.uint8) cv2.line(img, toint(p0), toint(p1), (0, 255, 0)) if n > 0: line_points = sample_line(p0, p1, n-outn, noise) outliers = np.random.rand(outn, 2) * (w, h) points = np.vstack([line_points, outliers]) for p in line_points: cv2.circle(img, toint(p), 2, (255, 255, 255), -1) for p in outliers: cv2.circle(img, toint(p), 2, (64, 64, 255), -1) func = getattr(cv2, cur_func_name) vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01) cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255)) draw_str(img, (20, 20), cur_func_name) cv2.imshow('fit line', img)
Example #3
Source File: fitline.py From PyCV-time with MIT License | 7 votes |
def update(_=None): noise = cv2.getTrackbarPos('noise', 'fit line') n = cv2.getTrackbarPos('point n', 'fit line') r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0 outn = int(n*r) p0, p1 = (90, 80), (w-90, h-80) img = np.zeros((h, w, 3), np.uint8) cv2.line(img, toint(p0), toint(p1), (0, 255, 0)) if n > 0: line_points = sample_line(p0, p1, n-outn, noise) outliers = np.random.rand(outn, 2) * (w, h) points = np.vstack([line_points, outliers]) for p in line_points: cv2.circle(img, toint(p), 2, (255, 255, 255), -1) for p in outliers: cv2.circle(img, toint(p), 2, (64, 64, 255), -1) func = getattr(cv2.cv, cur_func_name) vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01) cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255)) draw_str(img, (20, 20), cur_func_name) cv2.imshow('fit line', img)
Example #4
Source File: fitline.py From OpenCV-Python-Tutorial with MIT License | 7 votes |
def update(_=None): noise = cv2.getTrackbarPos('noise', 'fit line') n = cv2.getTrackbarPos('point n', 'fit line') r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0 outn = int(n*r) p0, p1 = (90, 80), (w-90, h-80) img = np.zeros((h, w, 3), np.uint8) cv2.line(img, toint(p0), toint(p1), (0, 255, 0)) if n > 0: line_points = sample_line(p0, p1, n-outn, noise) outliers = np.random.rand(outn, 2) * (w, h) points = np.vstack([line_points, outliers]) for p in line_points: cv2.circle(img, toint(p), 2, (255, 255, 255), -1) for p in outliers: cv2.circle(img, toint(p), 2, (64, 64, 255), -1) func = getattr(cv2, cur_func_name) vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01) cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255)) draw_str(img, (20, 20), cur_func_name) cv2.imshow('fit line', img)
Example #5
Source File: morphology.py From OpenCV-Python-Tutorial with MIT License | 6 votes |
def update(dummy=None): sz = cv2.getTrackbarPos('op/size', 'morphology') iters = cv2.getTrackbarPos('iters', 'morphology') opers = cur_mode.split('/') if len(opers) > 1: sz = sz - 10 op = opers[sz > 0] sz = abs(sz) else: op = opers[0] sz = sz*2+1 str_name = 'MORPH_' + cur_str_mode.upper() oper_name = 'MORPH_' + op.upper() st = cv2.getStructuringElement(getattr(cv2, str_name), (sz, sz)) res = cv2.morphologyEx(img, getattr(cv2, oper_name), st, iterations=iters) draw_str(res, (10, 20), 'mode: ' + cur_mode) draw_str(res, (10, 40), 'operation: ' + oper_name) draw_str(res, (10, 60), 'structure: ' + str_name) draw_str(res, (10, 80), 'ksize: %d iters: %d' % (sz, iters)) cv2.imshow('morphology', res)
Example #6
Source File: colorthresh.py From computer-vision with MIT License | 6 votes |
def onTrackbar(self, val): # OpenCV-Python seems to have issues with trackbars. Each trackbar's # linked variable is not updated when the trackbar position changes. # Creating a separate callback function for each trackbar (since a # reference to the trackbar is not passed to the callback function) # doesn't help. Seems when multiple trackbars are defined in the same # window, all trackbars call back to the callback function for the # last defined trackbar (in this case, the one corresponding to # ch2HighVal), regardless of which callback function was passed to them. # # Hence, I've opted to explicitly query each trackbar by name on any # trackbar change, regardless of which one was changed. self.ch0LowVal = cv2.getTrackbarPos("Ch0 Low", self.CTRL_WIN) self.ch0HighVal = cv2.getTrackbarPos("Ch0 High", self.CTRL_WIN) self.ch1LowVal = cv2.getTrackbarPos("Ch1 Low", self.CTRL_WIN) self.ch1HighVal = cv2.getTrackbarPos("Ch1 High", self.CTRL_WIN) self.ch2LowVal = cv2.getTrackbarPos("Ch2 Low", self.CTRL_WIN) self.ch2HighVal = cv2.getTrackbarPos("Ch2 High", self.CTRL_WIN) if self.mode == "image": self.thresholdImage()
Example #7
Source File: Transition.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 6 votes |
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 #8
Source File: deconvolution.py From PyCV-time with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #9
Source File: deconvolution.py From OpenCV-Python-Tutorial with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #10
Source File: morphology.py From PyCV-time with MIT License | 6 votes |
def update(dummy=None): sz = cv2.getTrackbarPos('op/size', 'morphology') iters = cv2.getTrackbarPos('iters', 'morphology') opers = cur_mode.split('/') if len(opers) > 1: sz = sz - 10 op = opers[sz > 0] sz = abs(sz) else: op = opers[0] sz = sz*2+1 str_name = 'MORPH_' + cur_str_mode.upper() oper_name = 'MORPH_' + op.upper() st = cv2.getStructuringElement(getattr(cv2, str_name), (sz, sz)) res = cv2.morphologyEx(img, getattr(cv2, oper_name), st, iterations=iters) draw_str(res, (10, 20), 'mode: ' + cur_mode) draw_str(res, (10, 40), 'operation: ' + oper_name) draw_str(res, (10, 60), 'structure: ' + str_name) draw_str(res, (10, 80), 'ksize: %d iters: %d' % (sz, iters)) cv2.imshow('morphology', res)
Example #11
Source File: MediaPlayer.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 6 votes |
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 #12
Source File: deconvolution.py From PyCV-time with MIT License | 6 votes |
def update(_): ang = np.deg2rad( cv2.getTrackbarPos('angle', win) ) d = cv2.getTrackbarPos('d', win) noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win)) if defocus: psf = defocus_kernel(d) else: psf = motion_kernel(ang, d) cv2.imshow('psf', psf) psf /= psf.sum() psf_pad = np.zeros_like(img) kh, kw = psf.shape psf_pad[:kh, :kw] = psf PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh) PSF2 = (PSF**2).sum(-1) iPSF = PSF / (PSF2 + noise)[...,np.newaxis] RES = cv2.mulSpectrums(IMG, iPSF, 0) res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT ) res = np.roll(res, -kh//2, 0) res = np.roll(res, -kw//2, 1) cv2.imshow(win, res)
Example #13
Source File: distrans.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): global need_update need_update = False thrs = cv2.getTrackbarPos('threshold', 'distrans') mark = cv2.Canny(img, thrs, 3*thrs) dist, labels = cv2.distanceTransformWithLabels(~mark, cv.CV_DIST_L2, 5) if voronoi: vis = cm[np.uint8(labels)] else: vis = cm[np.uint8(dist*2)] vis[mark != 0] = 255 cv2.imshow('distrans', vis)
Example #14
Source File: range_detector.py From ImageAnalysis with MIT License | 5 votes |
def get_trackbar_values(range_filter): values = [] for i in ["MIN", "MAX"]: for j in range_filter: v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars") values.append(v) return values
Example #15
Source File: range_detector-rg.py From ImageAnalysis with MIT License | 5 votes |
def get_trackbar_values(range_filter): values = [] for i in ["MIN", "MAX"]: for j in range_filter: v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars") values.append(v) return values
Example #16
Source File: plane_ar.py From PyCV-time with MIT License | 5 votes |
def draw_overlay(self, vis, tracked): x0, y0, x1, y1 = tracked.target.rect quad_3d = np.float32([[x0, y0, 0], [x1, y0, 0], [x1, y1, 0], [x0, y1, 0]]) fx = 0.5 + cv2.getTrackbarPos('focal', 'plane') / 50.0 h, w = vis.shape[:2] K = np.float64([[fx*w, 0, 0.5*(w-1)], [0, fx*w, 0.5*(h-1)], [0.0,0.0, 1.0]]) dist_coef = np.zeros(4) ret, rvec, tvec = cv2.solvePnP(quad_3d, tracked.quad, K, dist_coef) verts = ar_verts * [(x1-x0), (y1-y0), -(x1-x0)*0.3] + (x0, y0, 0) verts = cv2.projectPoints(verts, rvec, tvec, K, dist_coef)[0].reshape(-1, 2) for i, j in ar_edges: (x0, y0), (x1, y1) = verts[i], verts[j] cv2.line(vis, (int(x0), int(y0)), (int(x1), int(y1)), (255, 255, 0), 2)
Example #17
Source File: floodfill.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): if seed_pt is None: cv2.imshow('floodfill', img) return flooded = img.copy() mask[:] = 0 lo = cv2.getTrackbarPos('lo', 'floodfill') hi = cv2.getTrackbarPos('hi', 'floodfill') flags = connectivity if fixed_range: flags |= cv2.FLOODFILL_FIXED_RANGE cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags) cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1) cv2.imshow('floodfill', flooded)
Example #18
Source File: distrans.py From OpenCV-Python-Tutorial with MIT License | 5 votes |
def update(dummy=None): global need_update need_update = False thrs = cv2.getTrackbarPos('threshold', 'distrans') mark = cv2.Canny(img, thrs, 3*thrs) dist, labels = cv2.distanceTransformWithLabels(~mark, cv2.DIST_L2, 5) if voronoi: vis = cm[np.uint8(labels)] else: vis = cm[np.uint8(dist*2)] vis[mark != 0] = 255 cv2.imshow('distrans', vis)
Example #19
Source File: plane_ar.py From PyCV-time with MIT License | 5 votes |
def draw_overlay(self, vis, tracked): x0, y0, x1, y1 = tracked.target.rect quad_3d = np.float32([[x0, y0, 0], [x1, y0, 0], [x1, y1, 0], [x0, y1, 0]]) fx = 0.5 + cv2.getTrackbarPos('focal', 'plane') / 50.0 h, w = vis.shape[:2] K = np.float64([[fx*w, 0, 0.5*(w-1)], [0, fx*w, 0.5*(h-1)], [0.0,0.0, 1.0]]) dist_coef = np.zeros(4) ret, rvec, tvec = cv2.solvePnP(quad_3d, tracked.quad, K, dist_coef) verts = ar_verts * [(x1-x0), (y1-y0), -(x1-x0)*0.3] + (x0, y0, 0) verts = cv2.projectPoints(verts, rvec, tvec, K, dist_coef)[0].reshape(-1, 2) for i, j in ar_edges: (x0, y0), (x1, y1) = verts[i], verts[j] cv2.line(vis, (int(x0), int(y0)), (int(x1), int(y1)), (255, 255, 0), 2)
Example #20
Source File: floodfill.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): if seed_pt is None: cv2.imshow('floodfill', img) return flooded = img.copy() mask[:] = 0 lo = cv2.getTrackbarPos('lo', 'floodfill') hi = cv2.getTrackbarPos('hi', 'floodfill') flags = connectivity if fixed_range: flags |= cv2.FLOODFILL_FIXED_RANGE cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags) cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1) cv2.imshow('floodfill', flooded)
Example #21
Source File: distrans.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): global need_update need_update = False thrs = cv2.getTrackbarPos('threshold', 'distrans') mark = cv2.Canny(img, thrs, 3*thrs) dist, labels = cv2.distanceTransformWithLabels(~mark, cv2.DIST_L2, 5) if voronoi: vis = cm[np.uint8(labels)] else: vis = cm[np.uint8(dist*2)] vis[mark != 0] = 255 cv2.imshow('distrans', vis)
Example #22
Source File: coherence.py From PyCV-time with MIT License | 5 votes |
def update(): sigma = cv2.getTrackbarPos('sigma', 'control')*2+1 str_sigma = cv2.getTrackbarPos('str_sigma', 'control')*2+1 blend = cv2.getTrackbarPos('blend', 'control') / 10.0 print 'sigma: %d str_sigma: %d blend_coef: %f' % (sigma, str_sigma, blend) dst = coherence_filter(src, sigma=sigma, str_sigma = str_sigma, blend = blend) cv2.imshow('dst', dst)
Example #23
Source File: visual_hsv_bounds.py From robot-camera-platform with GNU General Public License v3.0 | 5 votes |
def get_trackbar_values(range_filter): values = [] for i in ["MIN", "MAX"]: for j in range_filter: v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars") values.append(v) return values
Example #24
Source File: object_finder.py From baxter_demos with Apache License 2.0 | 5 votes |
def colorDetect(self, img): #Blur the image to get rid of those annoying speckles blur_radius = cv2.getTrackbarPos("blur", processed_win) radius = cv2.getTrackbarPos("radius", processed_win) open_radius = cv2.getTrackbarPos("open", processed_win) blur_img = common.blurImage(img, blur_radius) if self.color == None and self.point is not None: self.color = blur_img[self.point[1], self.point[0]] print "segmenting color:", self.color return common.colorSegmentation(blur_img, blur_radius, radius, open_radius, self.color)
Example #25
Source File: object_finder.py From baxter_demos with Apache License 2.0 | 5 votes |
def edgeDetect(self, img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh1 = cv2.getTrackbarPos('threshold 1', edge_win) thresh2 = cv2.getTrackbarPos('threshold 2', edge_win) canny = cv2.Canny(gray, thresh1, thresh2) return canny
Example #26
Source File: object_finder.py From baxter_demos with Apache License 2.0 | 5 votes |
def updatePoint(self, event, x, y, flags, param): #blur the image and get a new color if event == cv2.EVENT_LBUTTONUP or event == cv2.EVENT_LBUTTONDOWN: blur_radius = cv2.getTrackbarPos("blur", processed_win) point = (x, y) self.point = point if self.cur_img is None: return blur_img = common.blurImage(self.cur_img, blur_radius) if self.color is None: self.color = blur_img[self.point[1], self.point[0]] self.axes = []
Example #27
Source File: object_finder.py From baxter_demos with Apache License 2.0 | 5 votes |
def updateDetector(self, args): maxSize = params['maxSize'] responseThreshold = cv2.getTrackbarPos("Response threshold", processed_win) lineThresholdProjected = cv2.getTrackbarPos("Projected line threshold", processed_win) lineThresholdBinarized = cv2.getTrackbarPos("Binarized line threshold", processed_win) self.detector = cv2.StarDetector(maxSize, responseThreshold, lineThresholdProjected, lineThresholdBinarized)
Example #28
Source File: trackbar.py From PyIntroduction with MIT License | 5 votes |
def value(self): return cv2.getTrackbarPos(self._param_name, self._win_name) # Trackbarの値を設定
Example #29
Source File: color_range_detector.py From Color-Tracker with MIT License | 5 votes |
def get_value(self): value = cv2.getTrackbarPos(self.name, self.parent_window_name) return value
Example #30
Source File: auto_marker.py From lightnet with MIT License | 5 votes |
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