-
大小: 113KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-06-06
- 语言: 其他
- 标签:
资源简介
利用Opencv和libdmtx识别 datamatrx ECC200二维码。可以识别旋转的非标准二维码。文件中包含了 libdmtx必需的链接库和头文件。
代码片段和文件信息
#include
#include “dmtx.h“
#include
using namespace std;
using namespace cv;
void ImgCorrection(Mat imageSource);
int main()
{
DmtxMessage *msg;
DmtxRegion *reg;
Mat src1 = imread(“rotateImg.jpg“0);
imshow(“原图“ src1);
ImgCorrection(src1);//执行该函数后,校正后的图片保存在工目录下
Mat src = imread(“corrImge.jpg“);
imshow(“原图校正后“ src);
if (!src.data){
cout << “Load image failed!“ << endl;
return 0;
}
cout << “非二维码识别:“ << endl;
DmtxImage *img;
img = dmtxImageCreate(src.data src.cols src.rows DmtxPack24bppRGB);
DmtxDecode *dec = dmtxDecodeCreate(img 1);
reg = dmtxRegionFindNext(dec NULL);
if (reg != NULL) {
msg = dmtxDecodeMatrixRegion(dec reg DmtxUndefined);
if (msg != NULL) {
cout << msg->output << endl;
dmtxMessageDestroy(&msg);
}
dmtxRegionDestroy(®);
}
dmtxDecodeDestroy(&dec);
dmtxImageDestroy(&img);
waitKey(0);
return 0;
}
//二维码的校正函数
void ImgCorrection(Mat imageSource)
{
Mat image;
imageSource.copyTo(image);
GaussianBlur(image image Size(3 3) 0); //滤波
threshold(image image 100 255 CV_THRESH_BINARY); //二值化
imshow(“二值化“ image);
Mat element = getStructuringElement(2 Size(7 7)); //膨胀腐蚀核
dilate(image image element);
imshow(“膨胀“ image);
Mat image1;
Laplacian(image image1 image.depth() 1);//拉普拉斯变换寻找边界
imshow(“边界“ image1);
//寻找直线
vectorlines;
HoughLines(image1 lines 1 CV_PI / 150 60 0 0);
Mat DrawLine = Mat::zeros(image1.size() CV_8UC1);
//Mat DrawLine = Mat::zeros(image1.size() image1.type());
for (int i = 0; i {
float rho = lines[i][0];
float theta = lines[i][1];
Point pt1 pt2;
double a = cos(theta) b = sin(theta);
double x0 = a*rho y0 = b*rho;
pt1.x = cvRound(x0 + 1000 * (-b));
pt1.y = cvRound(y0 + 1000 * a);
pt2.x = cvRound(x0 - 1000 * (-b));
pt2.y = cvRound(y0 - 1000 * a);
line(DrawLine pt1 pt2 Scalar(255) 1 CV_AA);
}
imshow(“直线“ DrawLine);
Point2f P1[4];
Point2f P2[4];
vectorcorners;
goodFeaturesToTrack(DrawLine corners 4 0.1 10 Mat()); //角点检测
cout << “角点坐标:“ << endl;
for (int i = 0; i {
circle(DrawLine corners[i] 3 Scalar(255) 3);
P1[i] = corners[i];
cout << corners[i].x << “ “ << corners[i].y << endl;
}
imshow(“交点“ DrawLine);
P2[0] = Point2f(0 0);
P2[1] = Point2f(0 imageSource.rows);
P2[2] = Point2f(imageSource.cols imageSource.rows);
P2[3] = Point2f(imageSource.cols 0);
Mat elementTransf;
elementTransf = getAffineTransform(P1 P2);
warpAffine(imageSource imageSource elementTransf imageSource.size() 1 0 Scalar(255));
imwrite(“corrImge.jpg“ imageSource);//校正后的图片保存
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 23867 2017-09-01 19:17 libdmtxTest\libdmtxTest\corrImge.jpg
文件 25214 2017-03-04 14:17 libdmtxTest\libdmtxTest\data_matrix_encode.jpg
文件 21398 2011-08-22 03:48 libdmtxTest\libdmtxTest\dmtx.h
文件 156672 2017-08-30 11:15 libdmtxTest\libdmtxTest\libdmtx.dll
文件 17904 2017-08-30 11:15 libdmtxTest\libdmtxTest\libdmtx.lib
文件 2908 2017-09-01 19:05 libdmtxTest\libdmtxTest\libdmtxTest.cpp
文件 4256 2017-08-30 11:21 libdmtxTest\libdmtxTest\libdmtxTest.vcxproj
文件 1069 2017-08-30 11:21 libdmtxTest\libdmtxTest\libdmtxTest.vcxproj.filters
文件 15154 2017-08-30 16:13 libdmtxTest\libdmtxTest\rotateImg.jpg
文件 979 2017-08-30 11:18 libdmtxTest\libdmtxTest.sln
..A..H. 22016 2017-09-01 19:17 libdmtxTest\libdmtxTest.v12.suo
目录 0 2017-09-01 19:17 libdmtxTest\libdmtxTest
目录 0 2017-09-01 19:17 libdmtxTest
----------- --------- ---------- ----- ----
291437 13
- 上一篇:STM32 驱动AD5412
- 下一篇:查看型钢截面特性小程序
评论
共有 条评论