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
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
autoCorrectionGetAngle
(String inputPath) 图像倾斜角度byteArrayToFloatList
(byte[] bytes) 将byte类型的arr转换成floatstatic float
bytes2Float
(byte[] arr) 将byte数组数据转换成floatstatic float[]
convertArray
(List<Float> floatList, Integer maxLength) static boolean
correctColor
(String imgPath, String resultPath) CLAHE(限制对比度自适应直方图均衡化)技术进行图像的色彩矫正static void
裁剪static void
croppedInnerImage
(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域内static void
croppedOuterImage
(String inputPath, String outputPath, int x, int y, int width, int height) 去除区域外static void
dctWaterMarkDecode
(String inputImgPath, String outputImgPath) 基于离散余弦变换(DCT)的水印解码功能static void
dctWaterMarkEncode
(String inputImgPath, String textWatermark, String outputImgPath) 基于离散余弦变换(DCT)的水印编码功能static void
denoiseImage
(String inputPath, String outputPath) 去噪 非局部均值去噪(Non-Local Means Denoising,NLMeans)static void
drawRedBox
(String inputPath, String outputPath, int x, int y, int width, int height) 区域内套红static void
edgeWeight
(String inputPath, String outputPath, Integer scope) 边缘像素加深/加浅,使用 Canny边缘检测找到边缘部分,如果是边缘,则进行边缘像素调整。static org.opencv.core.Mat
embedMessage
(org.opencv.core.Mat image, String message) static String
extractMessage
(org.opencv.core.Mat image) static double
faceCompare
(String img_1, String img_2) 人脸比对static void
filterBackgroundColor
(String inputPath, String outputPath, double colorThreshold) 过滤底色 首先将图像灰度化,像素值为0-255,数值越大越浅,比如可以把数值240以上的区域都填充成白色,就达到了过滤底色的目的。static void
gaussianBlur
(String inputPath, String outputPath) 高斯模糊 - 柔化static float[]
hogFeatureExtraction
(String imagePath, Integer widthOrHeight) HOG 特征提取器, 将原始图像灰度化,并且将原始图像缩放至相同大小后获得特征向量.static org.opencv.core.Mat
static org.opencv.core.Mat
static void
invertColors
(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 void
removeBlackEdge
(String inputPath, String outputPath, Integer blackEdgeWidth) 去黑边static org.opencv.core.Mat
resizeAndCenter
(org.opencv.core.Mat image, int targetWidth, int targetHeight) 根据目标尺寸与原始图像的比例来缩放图像,并确保在新图像中居中显示static void
旋转图像,并保持图像大小不变。static void
static double
similarityImage
(String image1Path, String image2Path, String type) 图像相似度static void
smoothBackground
(String inputPath, String outputPath, double colorThreshold) 背景色平滑static boolean
stitchImages
(String imgPath1, String imgPath2, String resultPath) 拼接融合两张图像并保存到指定路径,类似缝合图像的效果(两周图像有重叠的部分,类似分别拍多张图像后合并)static Boolean
templateMatching
(String sourceImg, String templateImg, String targetImg) 大图找小图static void
unsharpMasking
(String inputPath, String outputPath) Unsharp Masking 锐化 是一种通过从原始图像中减去一个模糊版本的图像来增强图像边缘的方法。static void
upSizeImage
(String inputPath, String outputPath, int width, int height) 补齐图像static boolean
whiteBalance
(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:
-
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:
-