

Initially, we get the webcam using VideoCapture(0). The next step is to use the Video Capture of OpenCV, which is quite simple. The function sketch_transform will transform the image into sketch like, applying Canny edge detector and imagem inversion. import cv2 from matplotlib import pyplot as plt def sketch_transform(image): image_grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) image_grayscale_blurred = cv2.GaussianBlur(image_grayscale, (7,7), 0) image_canny = cv2.Canny(image_grayscale_blurred, 10, 80) _, mask = image_canny_inverted = cv2.threshold(image_canny, 30, 255, cv2.THRESH_BINARY_INV) return mask In that particular example we used a sketch frame transformation applying Canny edge detector and image inversion.įirst, import the libraries.
#PYTHON OPENCV REGION OF INTEREST HOW TO#
Here we discuss the introduction, working of selectROI() function in OpenCV and examples respectively.This simple example shows how to include a rectangle inside a image, like a window for specific transformations. The output is shown in the snapshot above. Then we are displayed the cropped image as the output on the screen. Then we are cropping the area within the bounding box using imCrop() function. Then we are drawing the bounding box on the required object in the given image using selectROI() function. Then we are reading the image on which the bounding box is to be drawn using imread() function. In the above program, we are importing the required modules. Imageread = cv.imread('C:/Users/admin/Desktop/car.jpg') Imageread = cv.imread('C:/Users/admin/Desktop/plane.jpg')


#displaying the cropped image as the output on the screen #cropping the area of the image within the bounding box using imCrop() functionĬroppedimage = imageread):int(imagedraw+imagedraw), int(imagedraw):int(imagedraw+imagedraw)] #using selectROI() function to draw the bounding box around the required objects Imageread = cv.imread('C:/Users/admin/Desktop/educba.jpg') #reading the image on which bounding box is to be drawn using imread() function OpenCV program in python to demonstrate selectROI() function to draw a bounding box around a given object in the input image and then crop the area within the bounding box and then display the cropped image as the output on the screen. Given below are the examples of OpenCV bounding box: Example #1 Then the cropped image alone can be displayed as the output on the screen.Then the image within the bounding box drawn using selectROI() function can be cropped using imCrop() function.The selectROI() function returns an image by allowing us to draw the bounding box wherever necessary.The selectROI() function is used on the input image by passing it as the parameter to the selectROI() function to select the region of interest by drawing a bounding box around the required object.The image on which the bounding box is to be drawn using selectROI() function is read using imread() function.To draw a bounding box around an object in the given image, we make use of a function called selectROI() function in OpenCV.The bounding box is an imaginary rectangle drawn around a given object and it serves as the region of interest.Working of selectROI() Function in OpenCV source_image is the image on which the rectangular region can be selected, cropped and the cropped image can be displayed as the output on the screen.
