Package cn.net.pap.common.opencv
Class OpenCVUtils
java.lang.Object
cn.net.pap.common.opencv.OpenCVUtils
java opencv4.0.1 handle image
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleautoCorrectionGetAngle(String inputPath) 图像倾斜角度static DoubleautoCorrectionGetAngle2(String inputPath) 这个方法,传入的直接是已经生成边缘的图像 可以配合 ImageMagick 生成这个边缘图: magick 20.jpg -canny 0x1+10%+30% edges.pngbyteArrayToFloatList(byte[] bytes) 将byte类型的arr转换成floatstatic floatbytes2Float(byte[] arr) 将byte数组数据转换成floatstatic float[]convertArray(List<Float> floatList, Integer maxLength) static booleancorrectColor(String imgPath, String resultPath) CLAHE(限制对比度自适应直方图均衡化)技术进行图像的色彩矫正static void裁剪static voidcroppedInnerImage(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域内static voidcroppedOuterImage(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域外static voiddctWaterMarkDecode(String inputImgPath, String outputImgPath) 基于离散余弦变换(DCT)的水印解码功能static voiddctWaterMarkEncode(String inputImgPath, String textWatermark, String outputImgPath) 基于离散余弦变换(DCT)的水印编码功能static voiddenoiseImage(String inputPath, String outputPath) 去噪 非局部均值去噪(Non-Local Means Denoising,NLMeans)static voiddrawRedBox(String inputPath, String outputPath, int x, int y, int width, int height) 区域内套红static voidedgeWeight(String inputPath, String outputPath, Integer scope) 边缘像素加深/加浅,使用 Canny边缘检测找到边缘部分,如果是边缘,则进行边缘像素调整。static org.opencv.core.MatembedMessage(org.opencv.core.Mat image, String message) static StringextractMessage(org.opencv.core.Mat image) static org.opencv.core.Mateye(int rows, int cols, int type) static doublefaceCompare(String img_1, String img_2) 人脸比对static voidfilterBackgroundColor(String inputPath, String outputPath, double colorThreshold) 过滤底色 首先将图像灰度化,像素值为0-255,数值越大越浅,比如可以把数值240以上的区域都填充成白色,就达到了过滤底色的目的。static voidgaussianBlur(String inputPath, String outputPath) 高斯模糊 - 柔化static float[]hogFeatureExtraction(String imagePath, Integer widthOrHeight) HOG 特征提取器, 将原始图像灰度化,并且将原始图像缩放至相同大小后获得特征向量.static org.opencv.core.Matstatic org.opencv.core.Matstatic voidinvertColors(String inputPath, String outputPath, int x, int y, int width, int height) 反色static byte[]matOfKeyPointImage(String imagePath, Boolean resizeFlag, Integer targetWidth, Integer targetHeight) 图像特征static float[]matOfKeyPointImage2(String imagePath) static float[]matOfKeyPointImage3(String imagePath, Long arrayLength) 获得图像特征,可以指定特征长度。static float[]normalize(float[] data) 最大最小 归一化static voidremoveBlackEdge(String inputPath, String outputPath, Integer blackEdgeWidth) 去黑边static org.opencv.core.MatresizeAndCenter(org.opencv.core.Mat image, int targetWidth, int targetHeight) 根据目标尺寸与原始图像的比例来缩放图像,并确保在新图像中居中显示static void旋转图像,并保持图像大小不变。static voidstatic doublesimilarityImage(String image1Path, String image2Path, String type) 图像相似度static voidsmoothBackground(String inputPath, String outputPath, double colorThreshold) 背景色平滑static booleanstitchImages(String imgPath1, String imgPath2, String resultPath) 拼接融合两张图像并保存到指定路径,类似缝合图像的效果(两周图像有重叠的部分,类似分别拍多张图像后合并)static org.opencv.core.MatstitchImagesByPoint(org.opencv.core.Mat imageA, org.opencv.core.Mat imageB, org.opencv.core.Point iA, org.opencv.core.Point jA, org.opencv.core.Point iB, org.opencv.core.Point jB) 拼接 两张图像根据坐标点进行拼接.static BooleantemplateMatching(String sourceImg, String templateImg, String targetImg) 大图找小图static voidunsharpMasking(String inputPath, String outputPath) Unsharp Masking 锐化 是一种通过从原始图像中减去一个模糊版本的图像来增强图像边缘的方法。static voidupSizeImage(String inputPath, String outputPath, int width, int height) 补齐图像static booleanwhiteBalance(String imgPath, String resultPath) "灰度世界" 白平衡算法
-
Constructor Details
-
OpenCVUtils
public OpenCVUtils()
-
-
Method Details
-
templateMatching
大图找小图- Parameters:
sourceImg- 原始大图 image abs path test image(https://sm.ms/image/S4wj2dLm5N1pM8c)templateImg- 模板小图 image abs path test image(https://sm.ms/image/9RV7wI6QfYJlxhn)targetImg- 匹配出来的结果 image abs path test image(https://sm.ms/image/QZPycMl3FSgihJ1)
-
similarityImage
图像相似度- Parameters:
image1Path- 图像1路径image2Path- 图像2路径type- 相似度算法: Histogram- Returns:
-
resizeAndCenter
public static org.opencv.core.Mat resizeAndCenter(org.opencv.core.Mat image, int targetWidth, int targetHeight) 根据目标尺寸与原始图像的比例来缩放图像,并确保在新图像中居中显示- Parameters:
image-targetWidth-targetHeight-- Returns:
-
matOfKeyPointImage
public static byte[] matOfKeyPointImage(String imagePath, Boolean resizeFlag, Integer targetWidth, Integer targetHeight) 图像特征- Parameters:
imagePath-- Returns:
-
matOfKeyPointImage2
-
matOfKeyPointImage3
获得图像特征,可以指定特征长度。- Parameters:
imagePath-arrayLength-- Returns:
-
hogFeatureExtraction
HOG 特征提取器, 将原始图像灰度化,并且将原始图像缩放至相同大小后获得特征向量.- Parameters:
imagePath-widthOrHeight-- Returns:
-
byteArrayToFloatList
将byte类型的arr转换成float- Returns:
-
bytes2Float
public static float bytes2Float(byte[] arr) 将byte数组数据转换成float- Parameters:
arr-- Returns:
-
convertArray
-
normalize
public static float[] normalize(float[] data) 最大最小 归一化- Parameters:
data-- Returns:
-
rotation
旋转图像,并保持图像大小不变。- Parameters:
inputPath- 待旋转图像的绝对路径outputPath- 旋转后图像的绝对路径angle- 角度,逆时针为正, 传入 45 代表 逆时针旋转45度。
-
rotation2
-
edgeWeight
边缘像素加深/加浅,使用 Canny边缘检测找到边缘部分,如果是边缘,则进行边缘像素调整。- Parameters:
inputPath-outputPath-scope- -60 加深
-
gaussianBlur
高斯模糊 - 柔化- Parameters:
inputPath-outputPath-
-
unsharpMasking
Unsharp Masking 锐化 是一种通过从原始图像中减去一个模糊版本的图像来增强图像边缘的方法。- Parameters:
inputPath-outputPath-
-
drawRedBox
public static void drawRedBox(String inputPath, String outputPath, int x, int y, int width, int height) 区域内套红- Parameters:
inputPath-outputPath-x-y-width-height-
-
removeBlackEdge
去黑边- Parameters:
inputPath-outputPath-blackEdgeWidth- 外的处理,假设四周黑色边框的宽度是 blackEdgeWidth 个像素
-
croppedInnerImage
public static void croppedInnerImage(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域内- Parameters:
inputPath-outputPath-x-y-width-height-
-
croppedOuterImage
public static void croppedOuterImage(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域外- Parameters:
inputPath-outputPath-x-y-width-height-
-
cropImage
public static void cropImage(String inputPath, String outputPath, int x, int y, int width, int height) 裁剪- Parameters:
inputPath-outputPath-x-y-width-height-
-
invertColors
public static void invertColors(String inputPath, String outputPath, int x, int y, int width, int height) 反色- Parameters:
inputPath-outputPath-x-y-width-height-
-
upSizeImage
补齐图像- Parameters:
inputPath-outputPath-width-height-
-
denoiseImage
去噪 非局部均值去噪(Non-Local Means Denoising,NLMeans)- Parameters:
inputPath-outputPath-
-
smoothBackground
背景色平滑- Parameters:
inputPath-outputPath-colorThreshold- 定义颜色相似性阈值 50.0
-
filterBackgroundColor
public static void filterBackgroundColor(String inputPath, String outputPath, double colorThreshold) 过滤底色 首先将图像灰度化,像素值为0-255,数值越大越浅,比如可以把数值240以上的区域都填充成白色,就达到了过滤底色的目的。- Parameters:
inputPath-outputPath-colorThreshold- 定义底色过滤阈值 240
-
autoCorrectionGetAngle
图像倾斜角度- Parameters:
inputPath-- Returns:
-
autoCorrectionGetAngle2
这个方法,传入的直接是已经生成边缘的图像 可以配合 ImageMagick 生成这个边缘图: magick 20.jpg -canny 0x1+10%+30% edges.png- Parameters:
inputPath-- Returns:
-
imread
-
imread
-
embedMessage
-
extractMessage
-
dctWaterMarkEncode
public static void dctWaterMarkEncode(String inputImgPath, String textWatermark, String outputImgPath) 基于离散余弦变换(DCT)的水印编码功能- Parameters:
inputImgPath-textWatermark-outputImgPath-
-
dctWaterMarkDecode
基于离散余弦变换(DCT)的水印解码功能- Parameters:
inputImgPath-outputImgPath-
-
faceCompare
人脸比对- Parameters:
img_1-img_2-- Returns:
- Throws:
Exception
-
stitchImages
拼接融合两张图像并保存到指定路径,类似缝合图像的效果(两周图像有重叠的部分,类似分别拍多张图像后合并)- Parameters:
imgPath1- 第一张图像的文件路径imgPath2- 第二张图像的文件路径resultPath- 拼接后图像的保存路径
-
correctColor
CLAHE(限制对比度自适应直方图均衡化)技术进行图像的色彩矫正- Parameters:
imgPath- 输入图像resultPath- 输出图像- Returns:
- 矫正后的图像
-
whiteBalance
"灰度世界" 白平衡算法- Parameters:
imgPath-resultPath-- Returns:
-
stitchImagesByPoint
public static org.opencv.core.Mat stitchImagesByPoint(org.opencv.core.Mat imageA, org.opencv.core.Mat imageB, org.opencv.core.Point iA, org.opencv.core.Point jA, org.opencv.core.Point iB, org.opencv.core.Point jB) 拼接 两张图像根据坐标点进行拼接.- Parameters:
imageA-imageB-iA-jA-iB-jB-- Returns:
-
eye
public static org.opencv.core.Mat eye(int rows, int cols, int type)
-