Nee*_*raj 2 c++ opencv image imagemagick image-processing
我想用图像缩略图填充轮廓。区域轮廓将具有不同的形状。我需要将缩略图作为图案读取并用该图像填充轮廓。例如

我更喜欢使用 opencv 的解决方案。但任何程序化方法都是可观的。
这是一个 OpenCV 解决方案。主要部分是:
这是一个示例代码:
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
// Template image
Mat3b img = imread("path_to_image");
// Create a circular mask
Mat1b mask(1000, 1000, uchar(0));
circle(mask, Point(500, 500), 500, Scalar(255), CV_FILLED);
// Or load your own mask
//Mat1b mask = imread("path_to_mask", IMREAD_GRAYSCALE)
// Compute number of repetition in x and y
int nx = (mask.cols / img.cols) + 1;
int ny = (mask.rows / img.rows) + 1;
// Create repeated pattern
Mat3b repeated = repeat(img, ny, nx);
// Crop to meet mask size
Mat3b crop = repeated(Rect(0, 0, mask.cols, mask.rows));
// Create a white image same size as mask
Mat3b result(mask.rows, mask.cols, Vec3b(255, 255, 255));
// Copy pattern with the mask
crop.copyTo(result, mask);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这将产生为result:
| 归档时间: |
|
| 查看次数: |
1933 次 |
| 最近记录: |