当前位置:网站首页>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
边栏推荐
- 补:注解(Annotation)
- 电钻、电锤、电镐的区别
- Installation and use of Apache bench (AB pressure test tool)
- leetcode007--判断字符串中的括号是否匹配
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Go reflection - go language Bible learning notes
- Error occurs when thymeleaf th: value is null
- La caméra Unity tourne avec la souris
- Leetcode005 -- delete duplicate elements in the array in place
- Redis command Encyclopedia
猜你喜欢

Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience

Small volume Schottky diode compatible with nsr20f30nxt5g

Recommended scheme for national production of electronic components of wireless keyboard

Druid -- JDBC tool class case

The perfect combination of collaborative process and multi process

Eight misunderstandings that should be avoided in data visualization

Practice and exploration of knowledge map visualization technology in meituan

What is a data island? Why is there still a data island in 2022?

test

Windows remote connection to redis
随机推荐
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
The programmer starts the required application with one click of window bat
Last day of 2017
Spark case - wordcount
Unity3D 实用技巧 - 理论知识库(一)
A lifetime of needs, team collaboration can play this way on cloud nailing applet
test
A heavy sword without a blade is a great skill
Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
补:注解(Annotation)
List&lt; Map&gt; Replication: light copy and deep copy
Record the ThreadPoolExecutor main thread waiting for sub threads
General enumeration constant class
Improving 3D object detection with channel wise transformer
Unity3d practical skills - theoretical knowledge base (I)
zynq平台交叉编译器的安装
Innovative practice of short video content understanding and generation technology in meituan
Basic operation of sequence table
leetcode003--判断一个整数是否为回文数