Trackbar created but not updating, i mean the image are not blending [closed]

asked 2019-01-23 13:29:37 -0600

Allaye gravatar image
 header file --------------------

class Blending
{
public:
    Blending(void)
    {
        alpha = beta = key = defaultvalue = 0;
    }

    static void Blend(int, void*);
    int Blended();
    //int imageinput();
     double alpha, beta;
     int  key;
     int defaultvalue;
};

cpp and main file----------

int maximumvalue = 100;
    int defaultvalue = 50;

    void Blending::Blend(int, void*)
    {

        Blending blean;
        blean.alpha = (double)blean.defaultvalue / 100;
        addWeighted(img, blean.alpha,img2, 1.0 - blean.alpha, 0, des);
        imshow("Blendimage", des);
    }

int main()
{

            Blending::Blend(defaultvalue, 0);
            createTrackbar("Blend", "Blendimage", &defaultvalue,maximumvalue,Blending::Blend);

        waitKey(0);
}

when i run the code everything works well but the images in the windows does not blend, any help

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by berak
close date 2019-01-23 14:01:56.290106

Comments

LBerger gravatar imageLBerger ( 2019-01-23 13:41:17 -0600 )edit

@Allaye, take a break from opencv, invest half a year at learnng basic things, your programming language, etc.

you never NEED a silly Blending class AT ALL.

for the failure -- you're instancing a new Blending instance inside Blending::Blend() (that's already facepalm), but now look at the constructor !

(it's setting everything to 0, so ofc. it won't blend anything)

berak gravatar imageberak ( 2019-01-23 13:54:50 -0600 )edit

thank but the code works when i remove the class from my code, that just my problem...

Allaye gravatar imageAllaye ( 2019-01-23 14:06:46 -0600 )edit

can you please tell me how to resolve the problem, when i remove the constructor the i get an error to initialize the class variable, so please how can you help.

Allaye gravatar imageAllaye ( 2019-01-23 14:16:28 -0600 )edit

@Allaye -- I already told you this, but you really need to read The C++ Programming Language by Stroustrup. Search for that on google and you'll find a free, pirated copy of the book, version 3. I would prefer if you bought it instead, of course. You need to get rid of those duplicate variables that exist outside of the class.

sjhalayka gravatar imagesjhalayka ( 2019-01-23 15:24:14 -0600 )edit

at first i wrote the code without classes, so i have to make the variable extern and declare the variable outside the cpp file, so later i decided to put the in a class and i forgot to remove the variable from the global scope

Allaye gravatar imageAllaye ( 2019-01-23 16:03:11 -0600 )edit

Good luck.

sjhalayka gravatar imagesjhalayka ( 2019-01-23 16:04:25 -0600 )edit