资源简介
java dell opencv 处理图片 识别数字,先将图片处理成灰色,然后腐蚀
代码片段和文件信息
package com.test;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class BankCardTest {
public final static String openVCLibPath=“C:\\codeinfos\\ocr\\java_opencv\\opencv\\x64\\opencv_java320.dll“;
public final static String imgPath=“C:\\codeinfos\\ocr\\java_opencv\\src\\com\\test\\timg.jpg“;
public final static String savePath=“C:\\idetools\\ocrimg4\\“;
static {
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// 注意程序运行的时候需要在VM option添加该行 指明opencv的dll文件所在路径
// -Djava.library.path=$PROJECT_DIR$\opencv\x64
// 或者直接加载
System.load(openVCLibPath);
}
public static void main(String[] args) throws Exception {
Mat srcMat = Imgcodecs.imread(imgPath);
Mat destMat = new Mat();
Imgproc.cvtColor(srcMat destMat Imgproc.COLOR_RGB2GRAY);// 转灰色
saveImage(mat2BufferedImage(destMat) “2“);
Mat binaryMat = new Mat(destMat.height() destMat.width() CvType.CV_8UC1);
Imgproc.threshold(destMat binaryMat 28 255 Imgproc.THRESH_BINARY);// 二值
saveImage(mat2BufferedImage(binaryMat) “3“);
Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT new Size(3 3));
Mat erodeMat = new Mat();
Imgproc.erode(binaryMat erodeMat element);// 3*3的图片去腐蚀
saveImage(mat2BufferedImage(erodeMat) “4“);
// for (int y = 0; y < erodeMat.height(); y++)
// {
// for (int x = 0; x < erodeMat.width(); x++)
// {
// //得到该行像素点的值
// double[] data = erodeMat.get(yx);
// for (int i1 = 0; i1 < data.length; i1++) {
// data[i1] = 255;//像素点都改为白色
// }
// erodeMat.put(yxdata);
// }
// }
// for (int y = 0; y < erodeMat.height(); y++) {
// for (int x = 0; x < erodeMat.width(); x++) {
// // 得到该行像素点的值
// double[] data = erodeMat.get(y x);
// for (int i1 = 0; i1 < data.length; i1++) {
// data[i1] = 255;// 像素点都改为白色
// }
// erodeMat.put(y x data);
// }
// }
Mat imgSrc = new Mat();
Imgproc.erode(binaryMat imgSrc element);
int a = 0;
int b = imgSrc.height();
int state = 0;
int imgN = 5;
do {
for (int y = 0; y < imgSrc.height(); y++) {
int count = 0;
for (int x = 0; x < imgSrc.width(); x++) {
// 得到该行像素点的值
byte[] data = new byte[1];
imgSrc.get(y x data);
if (data[0] == 0)
count = count + 1;
}
if (state == 0)// 还未到有效行
{
if (count >= 150)// 找到了开始行
{// 有效行允许十个像素点的噪声
a = y;
state = 1;
}
} else if (state == 1) {
if (count <= 100)// 找到了结束行
{// 有效行允许十个像素点的噪声
b = y;
state = 2;
break;
}
}
}
System.out.println(“过滤下界“ + Integer.toString(a));
System.out.println(“过滤
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-02-09 16:32 java_opencv\
目录 0 2018-01-16 10:41 java_opencv\java_opencv\
文件 362 2017-12-22 13:04 java_opencv\java_opencv\.classpath
文件 387 2017-12-22 12:36 java_opencv\java_opencv\.project
目录 0 2018-01-16 10:41 java_opencv\java_opencv\.settings\
文件 598 2017-12-22 12:36 java_opencv\java_opencv\.settings\org.eclipse.jdt.core.prefs
目录 0 2018-01-16 10:41 java_opencv\java_opencv\bin\
目录 0 2018-01-16 10:41 java_opencv\java_opencv\bin\com\
目录 0 2018-01-16 10:41 java_opencv\java_opencv\bin\com\test\
文件 4681 2018-01-16 10:39 java_opencv\java_opencv\bin\com\test\BankCardTest.class
文件 12163 2017-12-26 14:05 java_opencv\java_opencv\bin\com\test\GasNumTest.class
文件 12495 2017-12-27 09:12 java_opencv\java_opencv\bin\com\test\GasNumTest2.class
文件 4872 2017-12-22 15:30 java_opencv\java_opencv\bin\com\test\Test1.class
文件 5045 2017-12-25 11:08 java_opencv\java_opencv\bin\com\test\Test2.class
文件 11692 2017-12-25 16:34 java_opencv\java_opencv\bin\com\test\Test3.class
文件 12151 2017-12-26 14:05 java_opencv\java_opencv\bin\com\test\Test4.class
文件 17130 2018-01-16 10:37 java_opencv\java_opencv\bin\com\test\timg.jpg
目录 0 2017-12-22 12:59 java_opencv\java_opencv\lib\
目录 0 2018-01-16 10:41 java_opencv\java_opencv\opencv\
文件 368013 2017-12-22 12:55 java_opencv\java_opencv\opencv\opencv-320.jar
目录 0 2018-01-16 10:41 java_opencv\java_opencv\opencv\x64\
文件 31758848 2017-12-22 12:55 java_opencv\java_opencv\opencv\x64\opencv_java320.dll
目录 0 2018-01-16 10:41 java_opencv\java_opencv\opencv\x86\
文件 26176512 2017-12-22 12:55 java_opencv\java_opencv\opencv\x86\opencv_java320.dll
目录 0 2018-01-16 10:41 java_opencv\java_opencv\src\
目录 0 2018-01-16 10:41 java_opencv\java_opencv\src\com\
目录 0 2018-01-16 10:42 java_opencv\java_opencv\src\com\test\
文件 4838 2018-01-16 10:39 java_opencv\java_opencv\src\com\test\BankCardTest.java
文件 17130 2018-01-16 10:37 java_opencv\java_opencv\src\com\test\timg.jpg
相关资源
- opencv-340.jar
- 基于opencv+java的银行卡图片处理
- android平台的车牌识别
- opencv_java411.zip
- 在android手机上使用opencv库识别静态人
- opencv图像处理(灰化,滤色,合成)
- openCv+java+spring boot
- window opencv_java320.dll
- 深入OpenCV Android应用开发中文高清完整
- android OpenCV研究之动态人脸识别
- javaOpenCV简单实现类似“全能扫描王”
- opencv-2.4.13.zip
- 《OpenCV Android开发实战》_贾志刚.pdf
- javacv-platform-1.5.1.zip
- opencv-4.2.0-vc14_vc15.7z
- opencv-4.1.2-android-sdk20191212.zip
- java_opencv人脸识别.zip
- opencv用到的jar包
- opencvextra_nonfree_install.zip
- OpenCV-Android-4.0.1
- OpenCV Android PDF+源码
- opencv.exe 安装包
- android端使用openCV实现车牌检测
- opencv-341.jar
- 4.3读取摄像头并显示
- java openCV 人脸识别 找茬
- opencv java api 手册
- opencv 2.4.9 2.4.10等版本
- android-opencv已经编译好的JAR库
- Android Opencv 人脸识别
评论
共有 条评论