Short Introduction : Area Extraction using Region of Interest(R…

Ahmad Mizan Nur Haq

Short Introduction : Area Extraction using Region of Interest(RoI)

·
Published in
·
2 min read
·
Jul 19, 2022
--
Today We are going to learn about how to extract area using Region of Interest pooling method. RoI widely used in object detection task.
In this article we will learn how RoI works with OpenCV in Python program. We need located the area first. Area Region of Interest (ROI) can be obtained by looking for the centroid of the image.
After we find the centroid of the image, we will make a bounding box that will be the area region of interest. To make it easier to see, lets illustrate :

Python Code for RoI

First of all we need to install OpenCV package, in here because I already install it so I don’t put it in. You can install OpenCV from this site :

Import OpenCV and Numpy

import cv2import numpy as npimport imutilsimgpath = "tampak depan asli.png"img = cv2.imread(imgpath)
we also will define the file path and then read or load the file.

Resize Image

height, width = 500, 500imgResize = cv2.resize(img,(height,width), interpolation=cv2.INTER_AREA)
Why we need to resize the image?, actually You don’t need to resize the image, but if the original image have inconsistent dimension that sometimes too long vertically or horizontally, We will lose a lot of features in the image. So we will resize the original image using interpolation method.

Region of Interest (RoI)

cv2.rectangle(imgResize,(300,250),(320,270),(255,0,0),2)roi = imgResize[255:267, 305: 317]
This line will cropping out the region area of the image.

Display

cv2.imshow("resized", imgResize)cv2.imshow("roi", roi)cv2.waitKey(0)
And after we get the region, we could display the crop of the region area with this line.
Like this project
0

Posted Mar 28, 2025

Today We are going to learn about how to extract area using Region of Interest pooling method. RoI widely used in object detection task. In this article we wil…

Alfagift - Payment method & Order Tracking System
Alfagift - Payment method & Order Tracking System
BacaanKu : E-Bookstore & Reader Concept
BacaanKu : E-Bookstore & Reader Concept
Hey! You Forget to Clean Your Data
Hey! You Forget to Clean Your Data