当前位置:网站首页>3H proficient in opencv (V) - perspective transformation
3H proficient in opencv (V) - perspective transformation
2022-06-29 18:01:00 【Hua Weiyun】
| 0、 preparation |
|---|
Right click the new project , choice Python File, Create a new one Python file , Then at the beginning import cv2 Import cv2 library ,import numpy And rename to np.
import cv2import numpy as np
We also need to know where OpenCV in , The direction of the coordinate axis is x Shaft to the right ,y Axis down , The coordinate origin is in the upper left corner , For example, the following one is 640 Pixels , Wide for 480 Pixel image .OK, Let's begin with this section .
| 1、 Scene description |
|---|
Given any image , Divide the area you need from it , And display it in the specified size . Moreover, the segmented image is parallel to the displayed window in the linear space . Like : I want to get the following K, In the original picture K It's lying obliquely , After segmentation, it should be displayed standing vertically . So how to achieve this effect ?
Before achieving the above effect , We need to get some important information , For example, playing cards in the picture above K Four coordinate points of . We can use the drawing tool to open this picture , Then place the mouse over the four points of the divided area , You can get the coordinate information .
Because the width and height axes of the image in the drawing are OpenCV It's the same , When I put the mouse over K At the top left corner , The bottom left corner of the drawing shows (734 Pixels ,185 Pixels ), This is the coordinate of the point in the upper left corner .
| 2、 Perspective transformation |
|---|
The implementation of the above requirements seems difficult , But with cv2 library , In fact, only 9 Line code .
- First, let's set the width of the output picture width by 250, high height by 350.
- Then read our pictures , This is the picture above .
- Define the four point coordinates of the target area , Respectively : Top left 、 The upper right 、 The lower left 、 The lower right . We've got... In the last step .
- pst2 Is the position of the output picture in the picture box , Select tile , Fixed writing .
- Use library functions
warpPerspectiveRealize perspective transformation , If you are interested, you can have an in-depth understanding of the principle . - Finally, output and display two images .
width,height=250,350img=cv2.imread("Resources/poker.jpg")pst1=np.float32([[734,185],[1101,266],[621,679],[1030,789]])pst2=np.float32([[0,0],[width,0],[0,height],[width,height]])matrix=cv2.getPerspectiveTransform(pst1,pst2)imgOutput=cv2.warpPerspective(img,matrix,(width,height))cv2.imshow("Image",img)cv2.imshow("Output",imgOutput)cv2.waitKey(0) Let's look at the effect , The picture on the left is our perspective transformation image , On the right is the original image :
The content of section 5 , It's really interesting , There are many applications in life . A thousand eyes is better than a thousand hands , Go and knock it again ~
边栏推荐
- Jar包后台启动并输出日志
- 【WebDriver】使用AutoIt上传文件
- You can do sideline work
- 图像特征计算与表示——基于内容的图像检索
- 工作流模块Jar包启动报错:liquibase – Waiting for changelog lock….
- Test dble split function execution + import time-consuming shell script reference
- Function independent watchdog (iwdg) experiment based on stm32f103zet6 Library
- Image feature computation and representation -- content based image retrieval
- Analyze the implementation principle of zero copy mechanism, applicable scenarios and code implementation
- Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
猜你喜欢
![[target tracking] |stark configuration win OTB](/img/29/a6b3b99b7d2349499aede9e76ab29a.png)
[target tracking] |stark configuration win OTB

阿里云不同账号新旧服务器镜像迁移数据迁移同步

基于注解和拦截器防止表单重复提交

Prevent form resubmission based on annotations and interceptors

力扣每日一题 06.29 两数相加

Force deduction daily question 06.29 add two numbers

NVIDIA installs the latest graphics card driver

Proxmox VE Install 7.2

Opencv+YOLO-V3实现目标跟踪

自动化软件测试 - 利用短信转发器结合Selenium读取短信验证码
随机推荐
位图的详细介绍及模拟实现
3H proficient in opencv (VI) - image stacking
Two controller layer interface authentication methods
PWM output experiment based on stm32f103zet6 library function
Maximum length of palindrome substring (string hash + binary)
kubekey2.2.1 kubernetes1.23.7离线包制作+harbor部暑并上传镜像
阿里云不同账号新旧服务器镜像迁移数据迁移同步
[tcapulusdb knowledge base] tcapulusdb system user group introduction
Xiaobai yuesai 51 supplement e g f
国内酒店交易DDD应用与实践——理论篇
【TcaplusDB知识库】TcaplusDB系统用户组介绍
Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
How to use the chart control of the b/s development tool devextreme - customize the axis position?
Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image
面试中问最常问的海量数据处理你拿捏了没?
Does rapid software delivery really need to be at the cost of security?
让 Google 搜索到自己的博客
Walk with love, educate and run poor families, and promote public welfare undertakings
Sword finger offer 13 Robot range of motion (BFS)
[wangdingbei 2020 Qinglong formation]areuserialz