鼠标处理创建第二个窗口(OPEN CV / C ++ / Win 10)

时间:2018-08-05 04:31:36

标签: c++ opencv computer-vision

我是Open CV的新手。我的问题是使用setMouseCallback时的第二个窗口。下面是我的代码。

String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
    try {

        //grab login form page first
        Response loginPageResponse = 
                Jsoup.connect("https://www.icloudemserp.com/corecampus/checkuser1.php")
                .referrer("https://www.icloudemserp.com/corecampus/index.php/")
                .userAgent(userAgent)
                .timeout(10 * 1000)
                .followRedirects(true)
                .method(Connection.Method.GET)        
                .execute();

        System.out.println("Fetched login page");

        //get the cookies from the response, which we will post to the action URL
        Map<String, String> mapLoginPageCookies = loginPageResponse.cookies();
        String YOUR_USER_ID = "MREI2033";
        String YOUR_PASSWORD = "student1234";
        String branch_id = "9";
        //lets make data map containing all the parameters and its values found in the form
        Map<String, String> mapParams = new HashMap<String, String>();
        mapParams.put("branchid", "1");
        mapParams.put("userid", "");
        mapParams.put("pass_word", "");
        mapParams.put("branchid", "9");
        mapParams.put("sel_acad_yr", "2013-2014");
        mapParams.put("sel_sem", "Sem+1");

        System.out.println("*****************************************"+YOUR_USER_ID+YOUR_PASSWORD);
        //URL found in form's action attribute
        String strActionURL = "https://www.icloudemserp.com/corecampus/checkuser1.php";

        Response responsePostLogin = Jsoup.connect(strActionURL) 
                //referrer will be the login page's URL
                .referrer("https://www.icloudemserp.com/corecampus/index.php/")
                //user agent
                .userAgent(userAgent)
                //connect and read time out
                .timeout(10 * 1000)
                //post parameters
                .data(mapParams)
                //cookies received from login page
                .cookies(mapLoginPageCookies)
                //many websites redirects the user after login, so follow them
                .followRedirects(true)
                .method(Connection.Method.POST)
                .execute();

        System.out.println("HTTP Status Code: " + responsePostLogin.statusCode());

        //parse the document from response
        Document document = responsePostLogin.parse();
        System.out.println(document);

        //get the cookies
        Map<String, String> mapLoggedInCookies = responsePostLogin.cookies();

        /*
         * For all the subsequent requests, you need to send
         * the mapLoggedInCookies containing cookies
         */
         Document doc = Jsoup.connect("https://www.icloudemserp.com/corecampus/student/student_index.php")
        .cookies(mapLoggedInCookies)
        .userAgent(userAgent)
        .get();
        System.out.println("##################################################");
        System.out.println(doc);
    }

主要功能。

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <vector>
#include <iostream>
#include <math.h>

using namespace cv;
using namespace std;

Point center, circumference;

// Source image
Mat image;
Mat source;

void drawCircle(int action, int x, int y, int flags, void *userdata)
{
    // Action to be taken when left mouse button is pressed
    if (action == EVENT_LBUTTONDOWN)
    {
        center = Point(x, y);
        cout << "DOWN";
        // Mark the center
        circle(source, center, 1, Scalar(255, 255, 0), 2, CV_AA);
    }
    // Action to be taken when left mouse button is released
    else if (action == EVENT_LBUTTONUP)
    {
        circumference = Point(x, y);
        // Calculate radius of the circle
        float radius = sqrt(pow(center.x - circumference.x, 2) +
            pow(center.y - circumference.y, 2));
        // Draw the circle
        circle(source, center, radius, Scalar(0, 255, 0), 2, CV_AA);
        imshow("Window", source);
    }
}

当我运行它时,它将使两个窗口具有相同的名称,第一个是显示我的图像,第二个是一个灰色窗口,它们的大小都相同,带有图像的窗口在灰色窗口上方。我的句柄仅在灰色窗口中起作用,当我在其上绘制时,它在窗口图像上绘制,灰色窗口看起来像我程序的句柄层。如何将其合并到一个窗口。 谢谢!!