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" #includeusing 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月17日 02时17分40秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
牛客国庆集训派对Day4——G 区间权值(找规律,双重前缀和)
2019-04-30
牛客国庆集训派对Day5——L 数论之神(找规律/数论)
2019-04-30
CodeForces - 629B Far Relative’s Problem(模拟)
2019-04-30
CodeForces - 1059B Forgery (思维)
2019-04-30
CodeForces - 456C Boredom (dp)
2019-04-30
CodeForces - 960B Minimize the error (思维,贪心)
2019-04-30
CodeForces - 97B Superset (思维/分治/构造)
2019-04-30
CodeForces - 675A Infinite Sequence(简单数论 细节)
2019-04-30
CodeForces - 1042B Vitamins (思维)
2019-04-30
ACM 2013 长沙区域赛 Collision (几何)
2019-04-30
ACM 2014 鞍山区域赛 E - Hatsune Miku (dp)
2019-04-30
反向传播&梯度下降 的直观理解程序(numpy)
2019-04-30
CodeForces - 931B World Cup (思维 模拟)
2019-04-30
ACM 2016 沈阳区域赛 E - Counting Cliques (dfs)
2019-04-30
ACM 2017 北京区域赛 J-Pangu and Stones(区间dp)
2019-04-30
HDU - 5643 King's Game (约瑟夫环变式)
2019-04-30
UVA - 1452 Jump (约瑟夫环变式)
2019-04-30