Negative value range for Trackbar in OpenCV

Viewed 2843

I am trying to include negative values in the range of the Trackbar of cv2.createTrackbar. But each time I run the script, the negative values are not considered.

How could I include the negative values?

import cv2
import numpy as np
from cv2 import CV_WINDOW_AUTOSIZE

def nothing(x):
   pass

cv2.namedWindow('image', flags = CV_WINDOW_AUTOSIZE)

cv2.createTrackbar('val1','image',-50,500, nothing)

This resets from 0 to 500, instead of staying at -50. How could I keep it from -50 to 500?

2 Answers

You can not do this. The issue has discussed on here.

However, you can go to the source code to change it. The guide is here. It seems to work for a lot of people.

As mentioned by Alejandro Silvestri, you can actually do this with setTrackbarMin

import cv2
import numpy as np
from cv2 import CV_WINDOW_AUTOSIZE

def nothing(x):
   pass

cv2.namedWindow('image', flags = CV_WINDOW_AUTOSIZE)

cv2.createTrackbar('val1', 'image', 0, 500, nothing) #<-- the '0' here is the default value

cv2.setTrackbarMin('val1', 'image', -50)
Related