vs2015+opencv3.3.1 +Eigen 3.3.4 c++实现 薄膜插值 泊松图像编辑(v=0||Δf=0)
发布日期:2022-04-04 06:36:24 浏览次数:15 分类:博客文章

本文共 2759 字,大约阅读时间需要 9 分钟。

#include "core/core.hpp"    #include "highgui/highgui.hpp"    #include "imgproc/imgproc.hpp"    #include "iostream"  #include 
using namespace std;using namespace cv;using namespace Eigen;int main(){ const string File = "789.jpg"; Mat imageSource = imread(File, 0); for (unsigned int i = 0; i < imageSource.rows; i++) for (unsigned j = 0; j < imageSource.cols; j++) if (imageSource.at
(i, j) != 0)imageSource.at
(i, j) = 255; namedWindow("Source Image"); imshow("Source Image", imageSource); Mat image; GaussianBlur(imageSource, image, Size(15, 15), 0); Canny(image, image, 100, 250); vector
> contours; vector
hierarchy; findContours(image, contours, hierarchy, RETR_LIST, CHAIN_APPROX_NONE, Point()); Mat imageContours = Mat::zeros(image.size(), CV_8UC1); Mat Contours = Mat::zeros(image.size(), CV_8UC1); //绘制 //contours[i]代表的是第i个轮廓,contours[i].size()代表的是第i个轮廓上所有的像素点数 int cont_area_M = 0; for (int i = 0; i < contours.size(); i++) { if (contourArea(contours[i])>cont_area_M) cont_area_M = contourArea(contours[i]); for (int j = 0; j < contours[i].size(); j++) { //绘制出contours向量内所有的像素点 Point P = Point(contours[i][j].x, contours[i][j].y); Contours.at
(P) = 255; } } //绘制轮廓 auto itc = contours.begin(); while (itc != contours.end()) { if (contourArea(*itc)
src1((rect.height + 2)*(rect.width + 2), (rect.height + 2)*(rect.width + 2)); VectorXd src20((rect.height + 2)*(rect.width + 2)); VectorXd src21((rect.height + 2)*(rect.width + 2)); VectorXd src22((rect.height + 2)*(rect.width + 2)); for (int i = rect.y - 1; i < rect.height + rect.y + 1; i++) for (int j = rect.x - 1; j < rect.width + rect.x + 1; j++) { p1.x = j; p1.y = i; if (pointPolygonTest(contours[0], p1, false) >0) { src1.insert(n, n) = 4; src1.insert(n, n - 1) = -1; src1.insert(n, n + 1) = -1; src1.insert(n, n - rect.width - 2) = -1; src1.insert(n, n + rect.width + 2) = -1; src20(n) = 0; src21(n) = 0; src22(n) = 0; } else { src1.insert(n, n) = 1; src20(n) = ima.at
(p1)[0]; src21(n) = ima.at
(p1)[1]; src22(n) = ima.at
(p1)[2]; }; ++n; } // cout << src1; VectorXd dst00; VectorXd dst01; VectorXd dst02; SparseLU
> solver; solver.analyzePattern(src1); solver.factorize(src1); dst00 = solver.solve(src20); dst01 = solver.solve(src21); dst02 = solver.solve(src22); n = 0; for (int i = rect.y - 1; i < rect.height + rect.y + 1; i++) for (int j = rect.x - 1; j < rect.width + rect.x + 1; j++) { ima.at
(i, j)[0] = dst00(n); ima.at
(i, j)[1] = dst01(n); ima.at
(i, j)[2] = dst02(n); n++; } imshow("Contours Image", imageContours); //轮廓 imshow("Point of Contours", Contours); //向量contours内保存的所有轮廓点集 imshow("Poin", ima); waitKey(0); system("pause"); return 0;}

 789.jpg 

 

7892.jpg

 

结果

 

大概十几s到40s出结果。

 

转载地址:https://www.cnblogs.com/l2017/p/8084867.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C++/C语言的标准库函数与运算符的区别new/delete malloc/free
下一篇:vs2015+opencv3.3.1 +Eigen 3.3.4 c++ 实现 泊松图像编辑(无缝融合)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月17日 02时17分40秒