psenet字符定位和warpAffine变换

部分代码实现:

Point2f center = minRect.center;//外接矩形中心点坐标
double angle = twoPointsAngel(vertices[0], vertices[1]);

Mat rot_mat = getRotationMatrix2D(center, 90-angle, 1.0);//求旋转矩阵
Mat rot_image;
Size dst_sz(im_bgr.size());
warpAffine(im_bgr, rot_image, rot_mat, dst_sz);//原图像旋转
//imshow("rot_image", rot_image);
//cv::waitKey();
int x = (center.x - (minRect.size.height / 2)) * w_scale;
int y = (center.y - (minRect.size.width / 2))* h_scale;
int h = minRect.size.width * w_scale;
int w = minRect.size.height* h_scale;

cv::Point points_0 = Point(vertices[0].x* w_scale, vertices[0].y* h_scale);
cv::Point points_1 = Point(vertices[1].x* w_scale, vertices[1].y* h_scale);
cv::Point points_2 = Point(vertices[2].x* w_scale, vertices[2].y* h_scale);
cv::Point points_3 = Point(vertices[3].x* w_scale, vertices[3].y* h_scale);

cv::line(im_bgr, points_0, points_1, color1, 2);
cv::line(im_bgr, points_1, points_2, color2, 2);
cv::line(im_bgr, points_2, points_3, color3, 2);
cv::line(im_bgr, points_3, points_0, color4, 2);

Mat result1 = rot_image(Rect(x, y, w, h));//提取ROI
//imshow("result", result1);
//waitKey();
char c[50];
_itoa(i++, c, 10);
strcat(c, ".jpg");
cv::imwrite(c, result1);

psenet身份证定位效果

cv::Point points[4];
for(int k=0;k<4;k++)
		points[k] = Point(vertices[k].x* w_scale, vertices[k].y* h_scale);
cv::line(im_bgr, points[0], points[1], color1, 2);
cv::line(im_bgr, points[1], points[2], color2, 2);
cv::line(im_bgr, points[2], points[3], color3, 2);
cv::line(im_bgr, points[3], points[0], color4, 2);

红、绿、蓝、黑

width:逆时针旋转与水平线夹角的第一条边;height:另一条边
angle:width边与水平线夹角,大小范围[0,-90]

 

cv::Point points_0 = Point(vertices[0].x* w_scale, vertices[0].y* h_scale);
cv::Point points_1 = Point(vertices[1].x* w_scale, vertices[1].y* h_scale);
cv::Point points_2 = Point(vertices[2].x* w_scale, vertices[2].y* h_scale);
cv::Point points_3 = Point(vertices[3].x* w_scale, vertices[3].y* h_scale);

cv::line(im_bgr, points_0, points_1, color1, 2);
cv::line(im_bgr, points_1, points_2, color2, 2);
cv::line(im_bgr, points_2, points_3, color3, 2);
cv::line(im_bgr, points_3, points_0, color4, 2);
		
Mat result1 = rot_image(Rect(x, y, w, h));//提取ROI

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值