openv对一个大图进行分割处理,最后合并成为一个大图的过程
2017-10-21 16:27
344 查看
这里主要是做身份证号识别处理用的!以备后续查看用。
这是原图
这是处理后的图
void main() { int pos[19] = { 0 }; Mat in_Inv = imread("d:/number.png",0); Mat img_threshold = Mat::zeros(in_Inv.rows, in_Inv.cols , srcImg.type()); for (int i = 0; i<18; i++) { pos[i] = i * img_threshold.cols / 18; } namedWindow("raw_img", 0); imshow("raw_img", in_Inv); Mat half1 = in_Inv(Rect(pos[0], 0, pos[1] - pos[0], in_Inv.rows)); Mat half2 = in_Inv(Rect(pos[1], 0, pos[2] - pos[1], in_Inv.rows)); Mat half3 = in_Inv(Rect(pos[2], 0, pos[3] - pos[2], in_Inv.rows)); Mat half4 = in_Inv(Rect(pos[3], 0, pos[4] - pos[3], in_Inv.rows)); Mat half5 = in_Inv(Rect(pos[4], 0, pos[5] - pos[4], in_Inv.rows)); Mat half6 = in_Inv(Rect(pos[5], 0, pos[6] - pos[5], in_Inv.rows)); Mat half7 = in_Inv(Rect(pos[6], 0, pos[7] - pos[6], in_Inv.rows)); Mat half8 = in_Inv(Rect(pos[7], 0, pos[8] - pos[7], in_Inv.rows)); Mat half9 = in_Inv(Rect(pos[8], 0, pos[9] - pos[8], in_Inv.rows)); Mat half10 = in_Inv(Rect(pos[9], 0, pos[10] - pos[9], in_Inv.rows)); Mat half11 = in_Inv(Rect(pos[10], 0, pos[11] - pos[10], in_Inv.rows)); Mat half12 = in_Inv(Rect(pos[11], 0, pos[12] - pos[11], in_Inv.rows)); Mat half13 = in_Inv(Rect(pos[12], 0, pos[13] - pos[12], in_Inv.rows)); Mat half14 = in_Inv(Rect(pos[13], 0, pos[14] - pos[13], in_Inv.rows)); Mat half15 = in_Inv(Rect(pos[14], 0, pos[15] - pos[14], in_Inv.rows)); Mat half16 = in_Inv(Rect(pos[15], 0, pos[16] - pos[15], in_Inv.rows)); Mat half17 = in_Inv(Rect(pos[16], 0, pos[17] - pos[16], in_Inv.rows)); Mat half18 = in_Inv(Rect(pos[17], 0, in_Inv.cols - pos[17], in_Inv.rows)); threshold(half1, half1, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half2, half2, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half3, half3, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half4, half4, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half5, half5, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half6, half6, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half7, half7, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half8, half8, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half9, half9, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half10, half10, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half11, half11, 0, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half12, half12, 180, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half13, half13, 160, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half14, half14, 160, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half15, half15, 160, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half16, half16, 160, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half17, half17, 160, 255, CV_THRESH_OTSU); //大津法二值化 threshold(half18, half18, 160, 255, CV_THRESH_OTSU); //大津法二值化 #if 0 namedWindow("half1", 0); imshow("half1", half1); namedWindow("half2", 0); imshow("half2", half2); namedWindow("half3", 0); imshow("half3", half3); namedWindow("half4", 0); imshow("half4", half4); namedWindow("half5", 0); imshow("half5", half5); namedWindow("half6", 0); imshow("half6", half6); namedWindow("half7", 0); imshow("half7", half7); namedWindow("half8", 0); imshow("half8", half8); namedWindow("half9", 0); imshow("half9", half9); namedWindow("half10", 0); imshow("half10", half10); namedWindow("half11", 0); imshow("half11", half11); namedWindow("half12", 0); imshow("half12", half12); namedWindow("half13", 0); imshow("half13", half13); namedWindow("half14", 0); imshow("half14", half14); namedWindow("half15", 0); imshow("half15", half15); namedWindow("half16", 0); imshow("half16", half16); namedWindow("half17", 0); imshow("half17", half17); namedWindow("half18", 0); imshow("half18", half18); #endif img_threshold = 0; Mat imageROI = img_threshold(Rect(pos[0], 0, pos[1] - pos[0], in_Inv.rows)); half1.copyTo(imageROI); imageROI = img_threshold(Rect(pos[1], 0, pos[2] - pos[1], in_Inv.rows)); half2.copyTo(imageROI); imageROI = img_threshold(Rect(pos[2], 0, pos[3] - pos[2], in_Inv.rows)); half3.copyTo(imageROI); imageROI = img_threshold(Rect(pos[3], 0, pos[4] - pos[3], in_Inv.rows)); half4.copyTo(imageROI); imageROI = img_threshold(Rect(pos[4], 0, pos[5] - pos[4], in_Inv.rows)); half5.copyTo(imageROI); imageROI = img_threshold(Rect(pos[5], 0, pos[6] - pos[5], in_Inv.rows)); half6.copyTo(imageROI); imageROI = img_threshold(Rect(pos[6], 0, pos[7] - pos[6], in_Inv.rows)); half7.copyTo(imageROI); imageROI = img_threshold(Rect(pos[7], 0, pos[8] - pos[7], in_Inv.rows)); half8.copyTo(imageROI); imageROI = img_threshold(Rect(pos[8], 0, pos[9] - pos[8], in_Inv.rows)); half9.copyTo(imageROI); imageROI = img_threshold(Rect(pos[9], 0, pos[10] - pos[9], in_Inv.rows)); half10.copyTo(imageROI); imageROI = img_threshold(Rect(pos[10], 0, pos[11] - pos[10], in_Inv.rows)); half11.copyTo(imageROI); imageROI = img_threshold(Rect(pos[11], 0, pos[12] - pos[11], in_Inv.rows)); half12.copyTo(imageROI); imageROI = img_threshold(Rect(pos[12], 0, pos[13] - pos[12], in_Inv.rows)); half13.copyTo(imageROI); imageROI = img_threshold(Rect(pos[13], 0, pos[14] - pos[13], in_Inv.rows)); half14.copyTo(imageROI); imageROI = img_threshold(Rect(pos[14], 0, pos[15] - pos[14], in_Inv.rows)); half15.copyTo(imageROI); imageROI = img_threshold(Rect(pos[15], 0, pos[16] - pos[15], in_Inv.rows)); half16.copyTo(imageROI); imageROI = img_threshold(Rect(pos[16], 0, pos[17] - pos[16], in_Inv.rows)); half17.copyTo(imageROI); imageROI = img_threshold(Rect(pos[17], 0, in_Inv.cols - pos[17], in_Inv.rows)); half18.copyTo(imageROI); namedWindow("processed_img", 0); imshow("processed_img", img_threshold); waitKey(0); }
这是原图
这是处理后的图
相关文章推荐
- 因为不想再程序中写循环,因此把UI页面需要更新的纪录的主键组成了一个以","隔开的字符串,将这个字符串传入存储过程中进行处理(转)
- 黑马程序员------ io流对一个图片文件进行分割与合并
- 使用java类SequenceInputStream 对一个文件进行分割和合并的操作
- 一个字符串分割处理的过程演示
- 编写一个程序,将 a.txt 文件中的单词与 b.txt 文件中的单词交替合并到 c.txt 文件中,a.txt 文件中的单词用回车符分隔,b.txt 文件中用回车或空格进行分隔。
- Tomcat处理一个HTTP请求的过程
- 建立一个存储和处理字符串的类DelCharStr。构造函数:动态申请存储字符串所需内存空间,并且即能用指定的字符串也能用默认的值0为所声明的对象进行初始化。
- Tomcat处理一个http请求的过程
- 将多个 SWF 文件合并为一个 SWF 以进行 iOS 部署
- 对一个表中相同的数据进行处理
- ,编写一个程序,将a.txt文件中的单词与b.txt文件中的单词交替合并到c.txt文件中,a.txt文件中的单词用回车符分隔,b.txt文件中用回车或空格进行分隔.
- 将website图片合并成一个大图,通过background-position来获取
- 已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序,要求用递归方法进行。
- Tomcat Server处理一个http请求的过程
- 存储过程内建临时表和临时函数,合并一个由存储过程返回的表
- js实现朝一个方向不间断的图片滚动,这是不能实现的(即最后一张图片跑完后紧接着进行第一张图片)
- 错误:在一个线程上创建的控件不能成为在另一个线程控件的父级(处理方法)
- 改变xAxis.data数据进行不合并处理
- 将一个制定分隔符的字符串进行分割
- 一个activity中多个handler和消息的处理过程