当前位置:网站首页>CLion+OpenCV identify ID number - detect ID number
CLion+OpenCV identify ID number - detect ID number
2022-04-23 04:44:00 【Vivid_ Mm】
OpenCV compile
1. download OpenCV windows Source code
2. install CMake( belt GUI Of )
3. download MinGW
4. Add environment variables (MinGW Of bin Contents and CMake Of bin Catalog )
5. stay OpenCV Source code build The same as creating in the directory build-mginw Folder
6. To configure CMake
If appear opencv_videoio For module error reporting, please refer to the following link
OPENCV compile Videoio Module problem solving _fengxueniu The blog of -CSDN Blog
CLion Environment building
Create a new project ;Cmakelist Import OpenCV
Cmakelist Add code :
cmake_minimum_required(VERSION 3.17)
project(IDdect)
set(CMAKE_CXX_STANDARD 14)
add_executable(IDdect main.cpp)
# Add code
set(OpenCV_DIR F:/opencvWin/opencv/build-mginw)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(IDdect ${OpenCV_LIBS})
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define DEFAULT_CARD_WIDTH 640
#define DEFAULT_CARD_HEIGHT 400
#define FIX_IDCARD_SIZE Size(DEFAULT_CARD_WIDTH,DEFAULT_CARD_HEIGHT)
int main() {
Mat dts;
Mat source_image;
Mat dst_img;
Mat src = imread("C:\\Users\\As10906\\Desktop\\pjl.jpg");
if(src.empty())
{
fprintf(stderr, "Can not load image\n");
return -1;
}
imshow("src",src);
// Compressed format
resize(src,src,FIX_IDCARD_SIZE);
// resize(src,src,Size(640,400),0,0,INTER_LINEAR);
imshow("resize",src);
source_image = src;
// grayscale
cvtColor(src,dts,COLOR_BGR2GRAY);
imshow("gray",dts);
// Two valued
threshold(dts,dts,100,255,CV_THRESH_BINARY);
imshow("threshold",dts);
// corrosion + inflation
Mat erodeElement = getStructuringElement(MORPH_RECT,Size(20,10));
erode(dts, dts, erodeElement);
imshow("erode",dts);
vector< vector<Point> > contours;
vector<Rect> rects;
findContours(dts, contours, rects,RETR_LIST, CHAIN_APPROX_SIMPLE, Point(0, 0));
for (int i = 0; i < contours.size(); i++)
{
Rect rect = boundingRect(contours.at(i));
rectangle(dts, rect, Scalar(0, 0, 255)); // stay dst The picture shows rect rectangular
imshow("rectangle",dts);
if (rect.width > rect.height * 11) {// Defined by aspect ratio 18 position 13:1
rects.push_back(rect);
// rectangle(source_image, rect, Scalar(0,255,255));//rect Is the coordinate that satisfies the scale Draw the coordinates that meet the conditions on the original drawing
// dst_img = source_image(rect);
// The reason for taking pictures may lead to the identification of the address or other row of the address as ID number.
}
}
// Robustness judgment --- Get the set coordinate points exceeding the scale rects, Then traverse and take out y The most valuable That is, closest to the bottom of the ID card
if(rects.size() ==1 ){
Rect rect = rects.at(0);
dst_img = source_image(rect);
}else{
int lowPoint = 0;
Rect finalRect;
for (int i = 0; i < rects.size(); ++i) {
Rect rect = rects.at(i);
// Point p = rect.tl();
if(rect.tl().y > lowPoint){
lowPoint = rect.tl().y;
finalRect = rect;
}
rectangle(source_image,finalRect,Scalar(255,255,0));
}
dst_img = source_image(finalRect);
}
imshow("aim",dst_img);
waitKey();// amount to VS Medium inputkey Blocking wait operation , Otherwise, all the picture effects will flash by
return 0;
}
Original picture :

effect :
At this point, I got the key picture of the ID number. , Next, import Android Studio Just identify the number in the picture
Rendering view path :https://download.csdn.net/download/xxwbwm/29939726
版权声明
本文为[Vivid_ Mm]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220558084168.html
边栏推荐
- L2-011 玩转二叉树(建树+BFS)
- 229. Find mode II
- C language: spoof games
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- What is the meaning of load balancing
- The perfect combination of collaborative process and multi process
- Differences among electric drill, electric hammer and electric pick
- Basic operation of sequence table
- 拼了!两所A级大学,六所B级大学,纷纷撤销软件工程硕士点!
- Use recyclerview to realize left-right side-by-side classification selection
猜你喜欢

Spark small case - RDD, spark SQL
![解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].](/img/99/095063b72390adea6250f7b760d78c.png)
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].

补充番外14:cmake实践项目笔记(未完待续4/22)

win10, mysql-8.0.26-winx64. Zip installation

Unity RawImage背景无缝连接移动

Recommended scheme for national production of electronic components for wireless charging

520. Detect capital letters

Practice and exploration of knowledge map visualization technology in meituan

针对NFT的网络钓鱼

Installation and deployment of Flink and wordcount test
随机推荐
Spark small case - RDD, broadcast
Supplement: Annotation
Improving 3D object detection with channel wise transformer
Recommended scheme of national manufactured electronic components for intelligent electronic scales
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
IDE idea automatic compilation and configuration of on update action and on frame deactivation
Leetcode001 -- returns the subscript of the array element whose sum is target
SQL statement for adding columns in MySQL table
补:注解(Annotation)
Practice and exploration of knowledge map visualization technology in meituan
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
selenium模式下切换窗口,抓取数据的实现
三十六计是什么
AWS eks add cluster user or Iam role
阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
协程与多进程的完美结合
数据孤岛是什么?为什么2022年仍然存在数据孤岛?
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
补充番外14:cmake实践项目笔记(未完待续4/22)
Com alibaba. Common methods of fastjson