Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

simple proportion ? you might use 0..100% as int range than scale it to your float range.

You can also choose the resolution value using a code like below

struct  myData {
    double thMin = 0.00001;
    double thMax = 0.001;
    double resolution = thMin / 2.0;
    double Range(){ return thMax - thMin; }
    int Ticks() { return cvRound(Range()/resolution); };
    int thInt = cvRound(Ticks() / 2.0); // start at 50%
};

void onTrackBar(int , void* userData)
{
    myData* pdata = (myData*)userData;

    double thFloat = pdata->thInt * pdata->Range() / pdata->Ticks();
    thFloat += pdata->thMin;
    //std::cout << cv::format("threshold: %0.5f", thFloat) << endl;
    std::cout << "threshold:" << thFloat << endl;
}

void main()
{
    myData data;
    static const char * winName = "MyWindow";
    cv::namedWindow(winName);
    cv::createTrackbar("Threshold", winName, &(data.thInt), data.Ticks(), onTrackBar, &data);
    onTrackBar(0, &data);
    cv::waitKey(0); // press a key on window
}

if you like 0..100% use int Ticks() { return 100; };

simple proportion ? you might use 0..100% as int range than scale it to your float range.

You can also choose the resolution value using a code like below

struct  myData {
    double thMin = 0.00001;
    double thMax = 0.001;
    double resolution = thMin / 2.0;
    double Range(){ return thMax - thMin; }
    int Ticks() { return cvRound(Range()/resolution); cvRound(Range() / resolution); };
    int thInt tbValue = cvRound(Ticks() / 2.0); // start at 50%
    double Value(){
        return thMin + tbValue * Range() / Ticks();
    }
};
 void onTrackBar(int , onTrackBar(int, void* userData)
{
    myData* pdata = (myData*)userData;
     double thFloat = pdata->thInt * pdata->Range() / pdata->Ticks();
    thFloat += pdata->thMin;
pdata->Value();
    //std::cout << cv::format("threshold: %0.5f", thFloat) << endl;
    std::cout << "threshold:" << thFloat << endl;
}
 void main()
{
    myData data;
    static const char * winName = "MyWindow";
    cv::namedWindow(winName);
    cv::createTrackbar("Threshold", winName, &(data.thInt), &(data.tbValue), data.Ticks(), onTrackBar, &data);
    onTrackBar(0, &data);
    cv::waitKey(0); cv::waitKey(1); // press a key on window
   ... put your code here ...
}

if you like 0..100% use int Ticks() { return 100; };

UPDATES

  • your code doesn't have any trackbar... use mine in double th = data.Value();// 0.00001;
  • your code can't work because cornerHarris requires Input single-channel 8-bit or floating-point image doc

Other tips:

Use std::vector<Point> S instead of Mat S(0, 2, CV_32SC1); and simply S.push_back(Point(i, j))

To checks whether a rectangle contains a point use Rec::contains:

Rect checkRect(Point(430, 285), Point(285, 315));
if (checkRect.contains(Point(i, j)))
    cout << "louis89" << endl;

simple proportion ? you might use 0..100% as int range than scale it to your float range.

You can also choose the resolution value using a code like below

struct  myData {
    double thMin = 0.00001;
    double thMax = 0.001;
    double resolution = thMin / 2.0;
    double Range(){ return thMax - thMin; }
    int Ticks() { return cvRound(Range() / resolution); };
    int tbValue = cvRound(Ticks() / 2.0); // start at 50%
    double Value(){
        return thMin + tbValue * Range() / Ticks();
    }
};
void onTrackBar(int, void* userData)
{
    myData* pdata = (myData*)userData;
    double thFloat = pdata->Value();
    //std::cout << cv::format("threshold: %0.5f", thFloat) << endl;
    std::cout << "threshold:" << thFloat << endl;
}
void main()
{
    myData data;
    static const char * winName = "MyWindow";
    cv::namedWindow(winName);
    cv::createTrackbar("Threshold", winName, &(data.tbValue), data.Ticks(), onTrackBar, &data);
    onTrackBar(0, &data);
    cv::waitKey(1); // press a key on window
   ... put your code here ...
}

if you like 0..100% use int Ticks() { return 100; };

UPDATES

  • your code doesn't have any trackbar... use mine in double th = data.Value();// 0.00001;
  • your code can't work because cornerHarris requires Input single-channel 8-bit or floating-point image doc

* THREAD UN-SAFE * Using trackbar to change a shared var fails in thread safety. Production grade application must use locks or other concurrency control.

Other tips:

Use std::vector<Point> S instead of Mat S(0, 2, CV_32SC1); and simply S.push_back(Point(i, j))

To checks whether a rectangle contains a point use Rec::contains:

Rect checkRect(Point(430, 285), Point(285, 315));
if (checkRect.contains(Point(i, j)))
    cout << "louis89" << endl;

simple proportion ? you might use 0..100% as int range than scale it to your float range.

You can also choose the resolution value using a code like below

struct  myData {
    double thMin = 0.00001;
    double thMax = 0.001;
    double resolution = thMin / 2.0;
    double Range(){ return thMax - thMin; }
    int Ticks() { return cvRound(Range() / resolution); };
    int tbValue = cvRound(Ticks() / 2.0); // start at 50%
    double Value(){
        return thMin + tbValue * Range() / Ticks();
    }
};
void onTrackBar(int, void* userData)
{
    myData* pdata = (myData*)userData;
    double thFloat = pdata->Value();
    //std::cout << cv::format("threshold: %0.5f", thFloat) << endl;
    std::cout << "threshold:" << thFloat << endl;
}
void main()
{
    myData data;
    static const char * winName = "MyWindow";
    cv::namedWindow(winName);
    cv::createTrackbar("Threshold", winName, &(data.tbValue), data.Ticks(), onTrackBar, &data);
    onTrackBar(0, &data);
    cv::waitKey(1); // press a key on window
   ... put your code here ...
}

if you like 0..100% use int Ticks() { return 100; };

UPDATES

  • your code doesn't have any trackbar... use mine in double th = data.Value();// 0.00001;
  • your code can't work because cornerHarris requires Input single-channel 8-bit or floating-point image doc

* THREAD UN-SAFE * UN-SAFE

Using trackbar to change a shared var fails in thread safety. Production grade application must use locks or other concurrency control.

Other tips:other tips

Use std::vector<Point> S instead of Mat S(0, 2, CV_32SC1); and simply S.push_back(Point(i, j))

To checks whether a rectangle contains a point use Rec::contains:

Rect checkRect(Point(430, 285), Point(285, 315));
if (checkRect.contains(Point(i, j)))
    cout << "louis89" << endl;

simple proportion ? you might use 0..100% as int range than scale it to your float range.

You can also choose the resolution value using a code like below

struct  myData {
    double thMin = 0.00001;
    double thMax = 0.001;
    double resolution = thMin / 2.0;
    double Range(){ return thMax - thMin; }
    int Ticks() { return cvRound(Range() / resolution); };
    int tbValue = cvRound(Ticks() / 2.0); // start at 50%
    double Value(){
        return thMin + tbValue * Range() / Ticks();
    }
};
void onTrackBar(int, void* userData)
{
    myData* pdata = (myData*)userData;
    double thFloat = pdata->Value();
    //std::cout << cv::format("threshold: %0.5f", thFloat) << endl;
    std::cout << "threshold:" << thFloat << endl;
}
void main()
{
    myData data;
    static const char * winName = "MyWindow";
    cv::namedWindow(winName);
    cv::createTrackbar("Threshold", winName, &(data.tbValue), data.Ticks(), onTrackBar, &data);
    onTrackBar(0, &data);
    cv::waitKey(1); // press a key on window
   ... put your code here ...
}

if you like 0..100% use int Ticks() { return 100; };

UPDATES

  • I can't see any trackbar in your code doesn't have any trackbar... code... use mine in double th = data.Value();// 0.00001;
  • your code can't work works because cornerHarris requires Input single-channel 8-bit or floating-point image doc

THREAD UN-SAFE

Using trackbar to change a shared var fails in thread safety. Production grade application must use locks or other concurrency control.

other tips

Use std::vector<Point> S instead of Mat S(0, 2, CV_32SC1); and simply S.push_back(Point(i, j))

To checks whether a rectangle contains a point use Rec::contains:

Rect checkRect(Point(430, 285), Point(285, 315));
if (checkRect.contains(Point(i, j)))
    cout << "louis89" << endl;