Ask Your Question

Bradleigh's profile - activity

2019-05-01 16:05:32 -0600 marked best answer How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255

Hello all, I am currently finding a solution to my problem very hard to come by what I want to do is create a trackbar with 10 settings corresponding to 0-255 and use this trackbar to carry out image thresholding.

I have tried all sorts of approaches and none have worked, I will show my code below.

import cv2





def bar(x):
pass


img = cv2.imread("messi5.png", cv2.IMREAD_GRAYSCALE)##Reads image from area in grayscale 
cv2.namedWindow("Image")##Names the window with the trackbar "image"
cv2.createTrackbar("R", "Image", 255, 10, bar)##Creates trackbar with values 0-10 



while True:##Loop for getting trackbar position and processing it 

R = cv2.getTrackbarPos('R','Image')
r=2*R
value_threshold = cv2.getTrackbarPos("R", "Image") == 199 ((199//25.5) +1) * 25,5 == 204) ##Gets trackbar position 

_, bar = cv2.threshold(img, value_threshold,  255,r, cv2.THRESH_BINARY)##Applies threshold





##Shows images in window 
##cv2.imshow("Image", img)
cv2.imshow("Image", bar)


key = cv2.waitKey(10)
if key == 27:##If escape is pressed break
    break

cv2.destroyAllWindows()

2019-05-01 16:05:32 -0600 received badge  Scholar (source)
2019-05-01 13:58:53 -0600 commented answer How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255

Thanks, I will try this shortly and let you know the outcome :)

2019-05-01 13:58:35 -0600 commented question How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255

I will try this and let you know the outcome :)

2019-05-01 11:35:43 -0600 asked a question How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255

How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255 Hello all, I am currently finding a solutio

2019-05-01 11:35:42 -0600 asked a question How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255

How to make the track bar move in steps e.g. step 1 = 25.5 and step 10= 255 Hello all, I am currently finding a solutio