openv对一个大图进行分割处理,最后合并成为一个大图的过程

2 篇文章 0 订阅
2 篇文章 0 订阅

这里主要是做身份证号识别处理用的!以备后续查看用。

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);
}

原图处理
这是原图
这是处理后的
这是处理后的图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值