openscan icon indicating copy to clipboard operation
openscan copied to clipboard

Edge Detect Sliders Not Responding

Open ryanpeach opened this issue 10 years ago • 0 comments

main.cpp

struct udata {
    Capture *capt;
    Par param;
} token;

Capture C;
int etol1, etol2, eSize, polyTol;
int cBlock, cSize, k, cThresh;

void setTrackBar(int v, void* userdata){
    cout << "Running setTrackBar..." << endl;
    udata t = *((udata*)(userdata));
    cout << t.param << " " << v << endl;
    (t.capt)->setValue((t.param), v);
}

void createTrackbar(String vname, String wname, int* v, int maxv, Capture* c, Par param) {
    token = {c, param}; 
    createTrackbar(vname, wname, v, maxv, &setTrackBar, &token);
}

void videoProcess(VideoCapture cap, Capture* c) {
    ...
    ...
    createTrackbar("eTol1", "Canny Edge Detection", &etol1, 255, c, ETOL1);
    createTrackbar("eTol2", "Canny Edge Detection", &etol2, 255, c, ETOL2); 
    createTrackbar("eSize", "Canny Edge Detection", &eSize, 21, c, ESIZE);
    createTrackbar("polyTol", "Polys, Rects, & Fps", &polyTol, 200, c, POLYTOL);
    createTrackbar("cBlock", "Polys, Rects, & Fps", &cBlock, 21, c, CBLOCK);
    createTrackbar("cSize", "Polys, Rects, & Fps", &cSize, 21, c, CSIZE);
    createTrackbar("k", "Polys, Rects, & Fps", &k, 21, c, K);
    createTrackbar("cThresh", "Polys, Rects, & Fps", &cThresh, 255, c, CTHRESH);
}

capture.cpp

namespace OPT {
const double VSCALE = 1000.0;
enum Method {fpcorners, strongborder, regular, automatic};
enum PageType {detect, letter};
enum Par {ANGLETOL, DISTTOL, POLYTOL, ASPECTRATIO, SIZERATIO, RATIOTOL, ETOL1, ETOL2, ESIZE, METHOD,
            CBLOCK, CSIZE, K, CTHRESH};
}

using namespace OPT;

void Capture::setValue(Par param, int value) {
    auto toDouble = [](int v) {return ((double)v)/VSCALE;};
    switch(param) {
        case ANGLETOL: angleTol = value; break;
        case DISTTOL: distTol = value; break;
        case POLYTOL: polyTol = value; break;
        case ASPECTRATIO: setAspectRatio((PageType)value); break;
        case SIZERATIO: sizeRatio = toDouble(value); break;
        case RATIOTOL: ratioTol = toDouble(value); break;
        case ETOL1: etol1 = value; break;
        case ETOL2: etol2 = value; break;
        case ESIZE: eSize = value; break;
        case CBLOCK: cBlock = value; break;
        case CSIZE: cSize = value; break;
        case K: k = value; break;
        case CTHRESH: cThresh = value; break;
        case METHOD: sel = (Method)value; break;
        default: break;
    }
}

When this is run, all the other sliders update their selected values, but ETOL1, ETOL2, and ESIZE appear not to. This may be because the param does not select the proper case statement due to pointer issues in the struct.

ryanpeach avatar Dec 02 '15 14:12 ryanpeach