4

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?

Jeremy
  • 189
  • 4
  • 14
  • 1
    You can't. Please read the [doc](https://docs.opencv.org/master/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b): _"The minimal position is always 0."_ – Miki Sep 07 '18 at 15:10

2 Answers2

3

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)
Zock77
  • 951
  • 8
  • 26
2

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.

MH Yip
  • 329
  • 1
  • 13