当前位置:网站首页>Practical puzzle solving | how to extract irregular ROI regions in opencv
Practical puzzle solving | how to extract irregular ROI regions in opencv
2022-07-04 14:26:00 【Xiaobai learns vision】
Click on the above “ Xiaobai studies vision ”, Optional plus " Star standard " or “ Roof placement ”
Heavy dry goods , First time delivery
What is? ROI
ROI It's English Region Of Interest Three acronyms of , Many times, our analysis of images is image specific ROI Analysis and understanding of , For cells and medical images ,ROI Only when the extraction is correct can subsequent analysis be carried out 、 measurement 、 Calculate density, etc , And these ROI The area is often not rectangular , Generally, it is an irregular polygon area , quite a lot OpenCV Beginners don't know how to extract these irregular ROI Area . Actually OpenCV There is a very convenient API Function can quickly extract all kinds of abnormal ROI Area .
extract ROI Area
Before doing this , First of all, let's know what is in image processing mask( Mask ),OpenCV It is defined in Mask Of : Eight bit single channel Mat object , Each pixel value is zero or non-zero area . When Mask When an object is added to the image area , Only non-zero regions are visible ,Mask All pixel values in the image are zero, and the area overlapped with the image will not be visible , in other words Mask The shape and size of the area directly determines the size and shape of the final image you see . A specific example is as follows :
It can be seen that ,mask The function of can Help us extract various irregular regions .OpenCV To complete the above steps, you only need to call API function bitwise_and that will do .
So another problem also follows , How can we generate such mask Area , The answer is OpenCV There are two ways to do it Mask Region generation .
Method 1 :
By manually selecting , Then you can do it through polygon filling , The code implementation is as follows :
import cv2 as cv
import numpy as np
src = cv.imread("D:/images/gc_test.png")
cv.imshow("input", src)
h, w, c = src.shape
# Hand drawn ROI Area
mask = np.zeros((h, w), dtype=np.uint8)
x_data = np.array([124, 169, 208, 285, 307, 260, 175])
y_data = np.array([205, 124, 135, 173, 216, 311, 309])
pts = np.vstack((x_data, y_data)).astype(np.int32).T
cv.fillPoly(mask, [pts], (255), 8, 0)
cv.imshow("mask", mask)
# according to mask, extract ROI Area
result = cv.bitwise_and(src, src, mask=mask)
cv.imshow("result", result)
cv.waitKey(0)
The operation effect is as follows :
Method 2 :
This is also OpenCV The most confused place for beginners , How to generate by program mask, It's really simple . Let's watch the code demonstration !
src = cv.imread("D:/images/gc_test.png")
cv.imshow("input", src)
# Generate mask Area
hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV)
mask = cv.inRange(hsv, (156, 43, 46), (180, 255, 255))
cv.imshow("mask", mask)
# extract ROI Area , according to mask
result = cv.bitwise_and(src, src, mask=mask)
cv.imshow("result", result)
cv.waitKey(0)
The effect is as follows :
It is mainly divided into three steps
Extract outline ROI
Generate Mask Area
Extract the specified contour
One thing in particular to note -> Which produces Mask According to the outline 、 Analysis of binary connected components 、inRange Wait for the processing method to get . Here is based on inRange The way to get mask Area , Then extract .
Practical application demonstration
Finally, let's see two that will be used in actual processing mask Realization ROI Extract and then re fuse the background to generate a new image effect :
The good news !
Xiaobai learns visual knowledge about the planet
Open to the outside world
download 1:OpenCV-Contrib Chinese version of extension module
stay 「 Xiaobai studies vision 」 Official account back office reply : Extension module Chinese course , You can download the first copy of the whole network OpenCV Extension module tutorial Chinese version , Cover expansion module installation 、SFM Algorithm 、 Stereo vision 、 Target tracking 、 Biological vision 、 Super resolution processing and other more than 20 chapters .
download 2:Python Visual combat project 52 speak
stay 「 Xiaobai studies vision 」 Official account back office reply :Python Visual combat project , You can download, including image segmentation 、 Mask detection 、 Lane line detection 、 Vehicle count 、 Add Eyeliner 、 License plate recognition 、 Character recognition 、 Emotional tests 、 Text content extraction 、 Face recognition, etc 31 A visual combat project , Help fast school computer vision .
download 3:OpenCV Actual project 20 speak
stay 「 Xiaobai studies vision 」 Official account back office reply :OpenCV Actual project 20 speak , You can download the 20 Based on OpenCV Realization 20 A real project , Realization OpenCV Learn advanced .
Communication group
Welcome to join the official account reader group to communicate with your colleagues , There are SLAM、 3 d visual 、 sensor 、 Autopilot 、 Computational photography 、 testing 、 Division 、 distinguish 、 Medical imaging 、GAN、 Wechat groups such as algorithm competition ( It will be subdivided gradually in the future ), Please scan the following micro signal clustering , remarks :” nickname + School / company + Research direction “, for example :” Zhang San + Shanghai Jiaotong University + Vision SLAM“. Please note... According to the format , Otherwise, it will not pass . After successful addition, they will be invited to relevant wechat groups according to the research direction . Please do not send ads in the group , Or you'll be invited out , Thanks for your understanding ~
边栏推荐
- 迅为IMX6Q开发板QT系统移植tinyplay
- How to operate and invest games on behalf of others at sea
- Xcode 异常图片导致ipa包增大问题
- Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
- 学内核之三:使用GDB跟踪内核调用链
- 测试流程整理(3)
- Leetcode T49: 字母异位词分组
- PyTorch的自动求导机制详细解析,PyTorch的核心魔法
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
猜你喜欢
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
实战解惑 | OpenCV中如何提取不规则ROI区域
使用CLion编译OGLPG-9th-Edition源码
基于51单片机的超声波测距仪
vscode 常用插件汇总
Data warehouse interview question preparation
Nowcoder reverse linked list
潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
C # WPF realizes the real-time screen capture function of screen capture box
按照功能对Boost库进行分类
随机推荐
软件测试之测试评估
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
10.(地图数据篇)离线地形数据处理(供Cesium使用)
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
产业互联网则具备更大的发展潜能,具备更多的行业场景
Popular framework: the use of glide
gin集成支付宝支付
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
电商系统中红包活动设计
第十六章 字符串本地化和消息字典(二)
MySQL triggers
Error in find command: paths must precede expression (turn)
redis 日常笔记
海外游戏代投需要注意的
Common content type correspondence table
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
Install and use MAC redis, connect to remote server redis
Visual Studio调试方式详解