void SegmentTrack::drawMap() { Mat img, img_scaled; // For drawing purposes convert positive values to 255, zero to 0. // Resulting drawing will be black and white existence map drawing this->M.convertTo(img, CV_8U, 255, 0); cvtColor(img,img,CV_GRAY2BGR); drawCursor(img); scaleUpMap(img, img_scaled, mapScaleFactor, mapScaleFactor); emit showTrackMap(mat2QImage(img_scaled)); }
void QImage2MatDialog::mat2qImageShow(QString& imagePath) { cv::Mat mat = cv::imread(_imageFilePath.toStdString(), IMREAD_UNCHANGED); qimageShow(mat2QImage(mat), ui->graphicsView_mat); }
//Calculates matching cost and show matching results on the window float GraphMatch::drawMatches(vector<NodeSig> ns1, vector<NodeSig> ns2, Mat img1, Mat img2) { Mat assignment, cost; //Construct [rowsxcols] cost matrix using pairwise //distance between node signature int rows = ns1.size(); int cols = ns2.size(); int** cost_matrix = (int**)calloc(rows,sizeof(int*)); for(int i = 0; i < rows; i++) { cost_matrix[i] = (int*)calloc(cols,sizeof(int)); for(int j = 0; j < cols; j++) { //Multiplied by constant because hungarian algorithm accept integer defined cost //matrix. We later divide by constant for correction cost_matrix[i][j] = GraphMatch::calcN2NDistance(ns1[i], ns2[j])*MULTIPLIER_1000; } } hungarian_problem_t p; // initialize the hungarian_problem using the cost matrix hungarian_init(&p, cost_matrix , rows, cols, HUNGARIAN_MODE_MINIMIZE_COST); // solve the assignment problem hungarian_solve(&p); //Convert results to OpenCV format assignment = array2Mat8U(p.assignment,rows,cols); cost = array2Mat32F(cost_matrix,rows,cols); //Divide for correction cost = cost / MULTIPLIER_1000; //free variables hungarian_free(&p); // Calculate match score and // show matching results given assignment and cost matrix Mat img_merged; float matching_cost = 0; //Concatenate two images hconcat(img1, img2, img_merged); //Get non-zero indices which defines the optimal match(assignment) vector<Point> nonzero_locs; findNonZero(assignment,nonzero_locs); //Draw optimal match for(int i = 0; i < nonzero_locs.size(); i++) { Point p1 = ns1[nonzero_locs[i].y].center; Point p2 = ns2[nonzero_locs[i].x].center+Point(img1.size().width,0); circle(img_merged,p1,MATCH_CIRCLE_RADIUS,MATCH_LINE_COLOR); circle(img_merged,p2,MATCH_CIRCLE_RADIUS,MATCH_LINE_COLOR); line(img_merged,p1,p2,MATCH_LINE_COLOR,MATCH_LINE_WIDTH); float dist = cost.at<float>(nonzero_locs[i].y, nonzero_locs[i].x); matching_cost = matching_cost + dist; //Draw cost on match image stringstream ss; ss << dist; string cost_str = ss.str(); Point center_pt((p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0); //putText(img_merged, cost_str, center_pt, cv::FONT_HERSHEY_SIMPLEX, 1.0, Scalar(255, 0, 0), 1); } //Show matching results image on the window emit showMatchImage(mat2QImage(img_merged)); return matching_cost; }