Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imho, all you need is this:

while(1) {
    double alpha=0:
    while ( alpha < (-11.0) || (double)alpha > 10.1) {
        cout << endl;
        cout << "Enter Your Blend Key from -11 to 10" << endl;
        cin >> alpha;
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha=0:
alpha=-12:
    while ( alpha < (-11.0) || (double)alpha alpha > 10.1) {
        cout << endl;
        cout << "Enter Your Blend Key from -11 to 10" << endl;
        cin >> alpha;
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha=-12:
alpha = -1; // invalid
    while ( alpha < (-11.0) 0.0 || alpha > 10.1) 1.0) {
        cout << endl;
        cout << "Enter Your Blend Key from -11 0.0 to 10" 1.0" << endl;
        cin >> alpha;
    }

    addWeighted(img, alpha, img2, alpha,  1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Key from 0.0 to 1.0" << endl;
        cin >> alpha;
    }

    addWeighted(img, alpha, img2, alpha,  1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Key from 0.0 to 1.0" << endl;
        cin >> alpha;
alpha; // while you console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0);
cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Key from 0.0 to 1.0" << endl;
        cin >> alpha; // while you your console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // initially invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Key Value from 0.0 to 1.0" << endl;
        cin >> alpha; // while your console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // initially invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Value from 0.0 to 1.0" << endl;
        cin >> alpha; // while your console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

edit

to ease your pain, ditch the cin, and use a trackbar, like this:

Mat img(300,300,CV_8UC3, Scalar(200,0,0));
Mat img2(300,300,CV_8UC3, Scalar(0,0,200));
Mat des;

int blend=50;
namedWindow("Blended");
createTrackbar("blend", "Blended", &blend, 100);

while(1) {
    double alpha = (double)blend / 100;

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(10);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // initially invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Value from 0.0 to 1.0" << endl;
        cin >> alpha; // while your console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

edit

to ease your pain, ditch the cin, and use a trackbar, like this:

Mat img(300,300,CV_8UC3, Scalar(200,0,0));
Mat img2(300,300,CV_8UC3, Scalar(0,0,200));
Mat des;

int blend=50;
namedWindow("Blended");
createTrackbar("blend", "Blended", &blend, 100);

while(1) {
    double alpha = (double)blend / 100;

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", imshow("blue", img);
    imshow("ime1", imshow("red", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(10);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

imho, all you need is this:

while(1) {
    double alpha = -1; // initially invalid
    while ( alpha < 0.0 || alpha > 1.0) {
        cout << endl;
        cout << "Enter Your Blend Value from 0.0 to 1.0" << endl;
        cin >> alpha; // while your console window has the focus !
    }

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("img", img);
    imshow("ime1", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(0); // while the highgui window has the focus !
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}

edit

to ease your pain, ditch the cin, and use a trackbar, like this:

Mat img(300,300,CV_8UC3, Scalar(200,0,0));
Mat img2(300,300,CV_8UC3, Scalar(0,0,200));
Mat des;

int blend=50;
// opencv maintains an internal, hidden list of windows, so make it a "known" one"
namedWindow("Blended");
// now we can add a trackbar, range [0..100]
createTrackbar("blend", "Blended", &blend, 100);

while(1) {
    double alpha = (double)blend / 100;

    addWeighted(img, alpha, img2, 1.0 - alpha, 0, des);
    imshow("blue", img);
    imshow("red", img2);
    imshow("Blended", des);

    char  key = cv::waitKey(10);
    if (key == 'Q' || key =='q' || key == 'E' || key =='e' )
         return EXIT_SUCCESS;
}