OpenCV的+安卓+号牌识别(OpenCV + Android + 图像水平矫正)

简介: /** * 价签矫正 */public void getContouresPic (Bitmap source) { Mat imageSobleOutThreshold = new Mat(); Mat gray = new Mat(); Utils.
/**
 * 价签矫正
 */
public void getContouresPic (Bitmap source) {
    Mat imageSobleOutThreshold = new Mat();

    Mat gray = new Mat();
    Utils.bitmapToMat(source, imageSobleOutThreshold);
    Imgproc.cvtColor(imageSobleOutThreshold, imageSobleOutThreshold, Imgproc.COLOR_BGR2GRAY);

    Imgproc.threshold(imageSobleOutThreshold, gray, 125, 225, Imgproc.THRESH_BINARY);//maxVal就是控制黑白反转的,0是黑

    //Utils.matToBitmap(gray, source);
    
    ArrayList<RotatedRect> rects = new  ArrayList<RotatedRect>();
    ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(gray, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);


    for(int i=0;i<contours.size();i++){
        Rect rect = Imgproc.boundingRect(contours.get(i));
        if (rect.width > 500 && rect.width/rect.height == 1) {
            MatOfPoint2f mp2f = new MatOfPoint2f(contours.get(i).toArray());
            RotatedRect mr = Imgproc.minAreaRect(mp2f);

            double area = Math.abs(Imgproc.contourArea(mp2f));

            double angle = mr.angle+90;

            Mat ratationedImg = new Mat(gray.rows(), gray.cols(), CvType.CV_8UC3);
            ratationedImg.setTo(new Scalar(0, 0, 0));



            Point center = mr.center;//中心点
            Mat m2 = Imgproc.getRotationMatrix2D(center, angle, 1);
            Imgproc.warpAffine(imageSobleOutThreshold, ratationedImg, m2, imageSobleOutThreshold.size(), 1, 0, new Scalar(0) );//仿射变换


            Utils.matToBitmap(ratationedImg, source);

            
            File file = new File(Environment.getExternalStorageDirectory()+"/AiLingGong/", "ll"+System.currentTimeMillis()+".jpg");
            try {
                FileOutputStream out = new FileOutputStream(file);
                source.compress(Bitmap.CompressFormat.JPEG, 100, out);
                out.flush();
                out.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Log.d("----------------", "旋转角度是:"+angle+"------"+"-----"+mr);

        }
        
        }
}

目录
相关文章
|
3月前
|
计算机视觉 Python
opencv识别颜色
opencv识别颜色
|
4月前
|
数据管理 API 数据库
探索Android Jetpack:现代安卓开发的利器
Android Jetpack是谷歌为简化和优化安卓应用开发而推出的一套高级组件库。本文深入探讨了Jetpack的主要构成及其在应用开发中的实际运用,展示了如何通过使用这些工具来提升开发效率和应用性能。
|
2月前
|
Android开发
我的Android进阶修炼:安卓启动流程之init(1)
本文深入分析了Android系统中的init进程,包括其源码结构、主要功能以及启动流程的详细注解,旨在帮助读者理解init作为用户空间的1号进程在Android启动过程中的关键作用。
31 1
|
2月前
|
Java 网络安全 开发工具
UNITY与安卓⭐一、Android Studio初始设置
UNITY与安卓⭐一、Android Studio初始设置
|
3月前
|
机器学习/深度学习 数据采集 算法
Python基于OpenCV和卷积神经网络CNN进行车牌号码识别项目实战
Python基于OpenCV和卷积神经网络CNN进行车牌号码识别项目实战
138 19
|
3月前
|
机器学习/深度学习 人工智能 文字识别
文本,文字扫描01,OCR文本识别技术展示,一个安卓App,一个简单的设计,文字识别可以应用于人工智能,机器学习,车牌识别,身份证识别,银行卡识别,PaddleOCR+SpringBoot+Andr
文本,文字扫描01,OCR文本识别技术展示,一个安卓App,一个简单的设计,文字识别可以应用于人工智能,机器学习,车牌识别,身份证识别,银行卡识别,PaddleOCR+SpringBoot+Andr
|
4月前
|
开发工具 Android开发 开发者
Android `.9.png` 图像是用于UI的可拉伸格式,保持元素清晰度和比例
【6月更文挑战第26天】Android `.9.png` 图像是用于UI的可拉伸格式,保持元素清晰度和比例。通过边上的黑线定义拉伸区域,右下角黑点标识内容区域,适应文本或组件大小变化。常用于按钮、背景等,确保跨屏幕尺寸显示质量。Android SDK 提供`draw9patch.bat`工具来创建和编辑。**
235 6
|
4月前
|
人工智能 安全 物联网
【Android】安卓开发的前景
【Android】安卓开发的前景
84 1
|
4月前
|
Android开发
在Android上实现图像颜色过滤与反转
在Android上实现图像颜色过滤与反转
117 0
在Android上实现图像颜色过滤与反转
|
4月前
|
移动开发 算法 计算机视觉
技术笔记:openCV特征点识别与findHomography算法过滤
技术笔记:openCV特征点识别与findHomography算法过滤
72 0
下一篇
无影云桌面