用鼠标截取图像并保存(2)

       用鼠标截取图像并保存(一)后续:


      此次试验主要是相对上一个实验,利用每个字符切割的初始位置不一样,改变切割的起点达到切割每个字符的目的。代码的改变主要是初始坐标和实时坐标的变化,即如下所示:

 {

                  dst = src(Rect(min(cur_pt.x, pre_pt.x), min(cur_pt.y, pre_pt.y), width, height));

                  namedWindow("dst")

                  imshow("dst", dst);


                  dst1 = src(Rect(min(cur_pt.x, pre_pt.x+58), min(cur_pt.y, pre_pt.y), width+15, height));

                  namedWindow("dst1");

                  imshow("dst1", dst1);

                   dst2 = src(Rect(min(cur_pt.x+100 , pre_pt.x+158), min(cur_pt.y, pre_pt.y), width, height));
                namedWindow("dst2");
                   imshow("dst2", dst2);

                   dst3 = src(Rect(min(cur_pt.x +158, pre_pt.x+223 ), min(cur_pt.y, pre_pt.y), width, height));
                namedWindow("dst3");
                   imshow("dst3", dst3);

                   dst4 = src(Rect(min(cur_pt.x +223, pre_pt.x+304 ), min(cur_pt.y, pre_pt.y), width, height));
               namedWindow("dst4");
                   imshow("dst4", dst4);

                   dst5= src(Rect(min(cur_pt.x+300, pre_pt.x +350), min(cur_pt.y, pre_pt.y), width, height));
              namedWindow("dst5");
                   imshow("dst5",dst5);


                   dst6= src(Rect(min(cur_pt.x + 360, pre_pt.x + 410), min(cur_pt.y, pre_pt.y), width, height));
              namedWindow("dst6");
                   imshow("dst6", dst6);
}


          通过鼠标找到所需的坐标点,计算出在X轴上初始坐标和实时坐标的变化,当鼠标切割第一个字符后,其余字符会同时被切割并显示出来,运行结果如下:









猜你喜欢

转载自blog.csdn.net/HHCCWWlxy/article/details/78796730