首页 技术 正文
技术 2022年11月14日
0 收藏 385 点赞 2,540 浏览 2632 个字
#include "core/core.hpp"
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
#include "iostream"
#include <Eigen/Sparse>
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<uchar>(i, j) != 0)imageSource.at<uchar>(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<vector<Point>> contours;
vector<Vec4i> 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<uchar>(P) = 255;}
}
//绘制轮廓 auto itc = contours.begin();while (itc != contours.end())
{
if (contourArea(*itc)<cont_area_M - 1)
itc = contours.erase(itc);
else
++itc;}drawContours(imageContours, contours, 0, Scalar(255), 1, 8, hierarchy, 0);Rect rect = boundingRect(contours[0]);Mat ima = imread("7892.jpg", 1);Point p1(0, 0);int n = 0;SparseMatrix< double, ColMajor> 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<Vec3b>(p1)[0];
src21(n) = ima.at<Vec3b>(p1)[1];
src22(n) = ima.at<Vec3b>(p1)[2];};
++n;
}
//cout << src1;VectorXd dst00; VectorXd dst01; VectorXd dst02;
SparseLU <SparseMatrix <double, ColMajor>> 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<Vec3b>(i, j)[0] = dst00(n);
ima.at<Vec3b>(i, j)[1] = dst01(n);
ima.at<Vec3b>(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 

vs2015+opencv3.3.1 +Eigen 3.3.4 c++实现 薄膜插值 泊松图像编辑(v=0||Δf=0)

7892.jpg

vs2015+opencv3.3.1 +Eigen 3.3.4 c++实现 薄膜插值 泊松图像编辑(v=0||Δf=0)

结果

vs2015+opencv3.3.1 +Eigen 3.3.4 c++实现 薄膜插值 泊松图像编辑(v=0||Δf=0)

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295