OpenCV的+安卓+号牌识别(OpenCV + Android + 图像水平矫正)
/** * 价签矫正 */ 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); } } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
基于Android官方AsyncListUtil优化经典ListView分页加载机制(二)
基于Android官方AsyncListUtil优化经典ListView分页加载机制(二) 我写的附录文章1,介绍了如何使用Android官方的分页加载框架AsyncListUtil优化改进常见的RecyclerView分页加载实现。AsyncListUtil作为一种通用的分页加载框架,不仅可以套用在RecyclerView,也可也适用在经典(传统)ListView中,下面给出一个简单例子,说明如何通过AsyncListUtil调整ListView的分页加载机制。 一个简单的MainActivity适用AsyncListUtil和ListView,展示分页加载: package zhangphil.app; import android.app.ListActivity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.os.SystemClock; import android.support.annotation.NonNu...
- 下一篇
cocos2d-x 创建工程详解
我们的编写的第一个程序一般习惯上都命名为HelloWorld,从它开始再学习其他的内容。下面介绍的第一个Cocos2d-x游戏我们也命名为HelloWorld。 创建工程 在Cocos2d-x早期版本中,创建工程是通过安装在Visual Studio中的工程模板而创建的,而目前创建工程Cocos2d-x是通过Cocos2d-x提供的命令工具cocos实现的,cocos位于<Cocos2d-x安装目录>\tools\cocos2d-console\bin下。我们能够通过DOS等终端进入bin目录执行下边的指令: cocos new HelloWorld-p com.work6 -l cpp -d D:/projects 其中D:/projects为HelloWorld的工程生成目录。通过上面的指令我们在D:/projects目录下面生成了名为HelloWorld的Cocos2d-x工程。打开HelloWorld目录。 从图中可以看出生成的工程代码是适合于多平台的,其中Classes目录是放置一些通用类(与平台无关的),我们编写的C++代码主要放置在该目录下面。图中cocos2...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7,CentOS8安装Elasticsearch6.8.6
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2全家桶,快速入门学习开发网站教程
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7