// two optimized connection diagram, such that natural splicing void OptimizeSeam(Mat& img1, Mat& trans, Mat& dst) { int start = MIN (corners.left_top.x, corners.left_bottom.x); // start position, i.e., the left boundary of the overlap region double processWidth = img1.cols - start; // width of overlapping region int rows = dst.rows; int cols = img1.cols; // Note that the number of channels is the number of columns * double alpha = 1; // img1 right pixels in weight for (int i = 0; i < rows; i++) { uchar * p = img1.ptr <uchar> (i); // get the first address of the i-th row * T = flying flying trans.ptr <> (i); UFOs flying d = dst.ptr <> (i); for (int j = start; j < cols; j++) { // If this is the image pixel trans no black spots, the full copy of the data img1 if (t[j * 3] == 0 && t[j * 3 + 1] == 0 && t[j * 3 + 2] == 0) { alpha = 1; } else { // img1 right pixels in weight, with the current proportional to the distance of the processing point from the left boundary of the overlap region, experiments show that this method is really good alpha = (processWidth - (j - start)) / processWidth; } d[j * 3] = p[j * 3] * alpha + t[j * 3] * (1 - alpha); d[j * 3 + 1] = p[j * 3 + 1] * alpha + t[j * 3 + 1] * (1 - alpha); d[j * 3 + 2] = p[j * 3 + 2] * alpha + t[j * 3 + 2] * (1 - alpha); } } }