Opencv area. Calculating the area of Bounding Box.

pts. countNonZero (image) – fmw42. With the rapid development in computer vision, Area Chairs help OpenCV in implementing state-of-the-art algorithms on a specific topic. Template class for 2D rectangles. threshold is used to apply the thresholding. 3) cut the image from contour. 5) The first parameter is the cv::aruco::Dictionary object previously created. Sep 29, 2017 · 2. The class represents rotated (i. So, you do not have to explicitly calculate the Hu Moments. convex. I set the interior of the contour to 255. findNonZero (mask) Here, two methods, one using Numpy functions, next one using Oct 17, 2020 · area = cv2. Sep 21, 2022 · contourArea() function calculates a contour area. 317884206771 128 I do understand the arc length function of the openCV, but what is this CONTOUR AREA? triangle. g. py which is an interactive tool using grabcut. In the following figure (made by @Knight), you can find a 2D slice of that cylinder, in V = 255, where the horizontal axis is the H and the vertical axis the S. It means that for each pixel location (x, y) in the source image (normally, rectangular), its neighborhood is considered and used to compute the response. I suspect NN stands for nearest neighbour, but I could be wrong. Jul 7, 2021 · The OpenCV function findContours() is used to detect contours in an image. Sep 3, 2016 · import cv2. This algorithm is enabled by using the flag, cv. described by the following parameters: Coordinates of the top-left corner. Just need to be carefuk about contour is closed or not and its self-intersection contour or not. After, we use numpy. This is a default interpretation of Rect_::x and Rect_::y in OpenCV. a list of points with elements x and y. I have tried to ensure the contour is closed to no avail. Then directly apply the grabCut function with mask mode. SimpleBlobDetector_create(params) C++. Code . OpenCV Area Chairs (and their teammates, if any) will create state-of-the-art algorithms and help shape the present and future of open source computer vision and AI. resizeはリサイズするために二つの方法が含んでいます。. INTER_CUBIC: This uses bicubic interpolation for resizing the image. 1) find contour (in this case rectangle, contour that is not rectangle is much harder to make) 2) find coordiantes of contour. out = cv2. v3 as iio. cv2. for example: x = np. Feb 22, 2017 · Areas with 0 would then be uncovered, 1 covered and 2 to n would mean covered by 2 to n images. In our case, we want to find the values that are equal to 255. Contours : More Functions. #include < opencv2/imgproc. , H=170 The functions in this section perform various geometrical transformations of 2D images. Feb 8, 2013 · 1. rectangle(img, pt1, pt2, color, thickness, lineType, shift) Draws a simple, thick, or filled up-right rectangle. Python: Aug 13, 2018 · The final step is to visualize the convex hulls we have just found. image, connectivity, ltype, ccltype [, labels] ) ->. Set a Region of Interest (ROI) Split and merge images. png', src2*255) # src2 (b) + src1 (a) = overlap (c) Hope that helps. contourArea (cnt) 3. It can be found out using cv. You integrate the area below each point going in clockwise direction. 1 1. A few weeks ago a PyImageSearch reader wrote in and asked about the best way to find the brightest spot in the image. Can you give me any suggestions to do it? Do I have to find the centro-ids of all the contours and check that they are residing in the given area ? Template class for specifying the size of an image or rectangle. zeros (imgray. You can use that size and roughly calculate the area of the blob. INTER_CUBIC (slow) & cv. How to calculate a marked area within boundary in SimpleCV or OpenCV. CV_INTER_AREA. In the code below, we use the macro CV_MAJOR_VERSION to detect the version of OpenCV. Calculating the area of Bounding Box. But to draw a rectangle, we need 4 corners of the rectangle. Jan 8, 2013 · Just mark the rectangle area in mask image with 2-pixel or 3-pixel (probable background/foreground). Jan 8, 2013 · Detailed Description. shape[0], thresh. 0. minAreaRect () for finding the minimum area rotated rectangle. Though, in your algorithms you may count x and y from the bottom-left corner. Every image that is read in, gets stored in a 2D array (for each color channel). Once they are obtained, color is filled to reduce minimum variance in that area. c++. not up-right) rectangles on a plane. We would like to show you a description here but the site won’t allow us. The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. Contour Features. Andyrey March 15, 2021, 4:06pm 5. imread ('my_image. You can change the code in the <textarea> to investigate more. Jun 16, 2017 · In specific, in OpenCV the Hue range is [0,179]. Aug 5, 2016 · This is stated: The function computes a contour area. 4. Jun 20, 2020 · In order to find the area of each contour, you can loop through the number of detected contour and use the function cv::contourArea () on each of those array of image coordinates. When resizing an image with cv2 resize, we need to keep in mind the image’s aspect ratio. Similarly to moments , the area is computed using the Green formula. crop the resulting area to its bounding box. I thought it would be a good idea to get the coordinates of the edges (number of edges change form object to object) or to get all coordinates of the contour and then use contourArea() to calculate the area of my object. So Feb 12, 2024 · cv2. are the points convex. Additional Resources Exercises . The size of the image can be specified manually, or you can specify the scaling factor. Then mark our sure_foreground with 1-pixel as we did in second example. uint8) cv. I have created an application that Segments an image on the basis of a predefined color using inRange function. The boundary region will be marked with -1. Image moments help you to calculate some features like center of mass of the object, area of the object etc. Second argument specify whether shape is a closed contour (if passed True), or just a curve. Is the list of contours out outputted by findContours() ordered in terms of area by default? Scaling is just resizing of the image. It is free for commercial use. Also, the function will most certainly give a wrong results for contours with self OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. Diving an Image into Small Patches. My question: does it return the number of pixels ?? Or if area then what is the unit of it. But most other image processing packages will have an area opening function. In OpenCV 3, the SimpleBlobDetector::create method is used to create a smart pointer. push_back (point3); return triangle; } // Run intersectConvexConvex on two polygons then draw the polygons and their intersection (if there is one) // Return the area of the intersection. Simply binarize the images and use matchShapes. INTER_LINEAR for Jan 20, 2021 · resized = cv2. The direction is given on the minimap by a cone where the area is brighter. Create new Mat of unsigned 8-bit chars, filled with zeros. 4. I need to convert the area into Mm2 and report it. Then if you want to find the proportion of the shape that is red, I would make another binary image of the original shape and then compare the areas. Jan 8, 2013 · For this, some methods from fluid dynamics are used. Open Source Computer Vision you may get seemingly odd results for contours with self-intersections, e. 10. Thus, the returned area and the number of non-zero pixels, if you draw the contour using drawContours or fillPoly , can be different. addWeighted( img, contrast, img, 0, brightness) output = cv2. color for the non-polygon area Jan 8, 2013 · OpenCV 3. crop. However, there appears to be a bug in the implementation in OpenCV 3. . One way I can do is parsing through each pixel value to calculate the average, but that is not an efficient way. This appears to happen when the contour is not closed. INTER_CUBIC: bicubic interpolation over 4 x 4 pixel neighborhood. as seen below arcLength contourArea 1000. void watershed (InputArray image, InputOutputArray markers) Performs a marker-based image segmentation using the watershed algorithm. whose two opposite corners are pt1 and pt2. Thus, the returned area and the number of non-zero pixels, if you draw the contour using drawContours or fillPoly, can be different. asked 2013-02-08 13:46:03 -0600. findNonZero (mask) Here, two methods, one using Numpy functions, next one using 2 days ago · Then marker image will be modified. Learn to find different features of contours like area, perimeter, bounding rectangle etc. They do not change the image content but deform the pixel grid and map this deformed grid to the destination image. minMaxLoc. contourArea(contour): Computes the area of the contour. Contours : Getting Started. Thanks mate that makes a lot of sense. You will learn plenty of functions related to contours. For the class of components with area 1 to 10 km2 (7 to 62 pixels), contourArea underestimates the area on average Jul 21, 2014 · So there you have it — detecting circles in images using OpenCV. and we have (x1,y1) as the top-left vertex and (x2,y2) as the bottom-right vertex of a rectangle region within that image, then: Mar 13, 2017 · The function selectROI also allows you to select multiple regions of interest, but there appear to be two bugs. color. You have to hit ENTER twice after the first rectangle. While resizing and interpolating new pixels, this method acts on the 4×4 OpenCV provides an easy to use a utility function called matchShapes that takes in two images ( or contours ) and finds the distance between them using Hu Moments. 6,420 3 33 60. py --image example_shapes. cv::minEnclosingCircle. OpenCV comes with a function cv. Moments. It is a multi-stage algorithm and we will go through each stages. Here is a simple code that does that. Contour Perimeter. use beta = 0 to effectively only operate one one image. Share Mar 15, 2017 · 2. X/OpenCV 3. submat (sel). It improves accuracy (because eyes are always on faces :D ) and performance (because we search in a small area). The image resizing function provided by Emgu (a . py , and insert the following code: return ((ptA[0] + ptB[0]) * 0. Closing. Several methods are available in OpenCV, the choice […] 2 days ago · Contours in OpenCV. area = cv. markers = cv. Apr 5, 2016 · I have detected all the contours withing a 640*480 image using openCV contour detection method. array [, binaryImage] ) ->. computes the connected components labeled image of boolean image. The structure can be converted to and from the old OpenCV structures CvSize and CvSize2D32f . There is such an optical science as ellipsometry. Fire up a shell, and execute the following command: $ python detect_circles. OpenCV defines the following Size_ <> aliases: Aug 3, 2017 · answered Aug 3 '17. Feb 20, 2015 · if you had a Rect called sel, making the mask is not difficult either: mask = Mat. Contour area is given by the function cv. The contours are represented as a list of points. Oct 20, 2015 · You can fill in the area that the contour occupies by specifying the thickness parameter to be -1. […] Jan 8, 2013 · Canny Edge Detection is a popular edge detection algorithm. nonzero (mask)) #pixelpoints = cv. watershed (img,markers) img [markers == -1] = [255,0,0] cv::watershed. OpenCV does not have this as a function, it can be implemented as shown in other answers. Jan 8, 2013 · To find the different features of contours, like area, perimeter, centroid, bounding box etc. Jun 28, 2014 · I have a set of points and would like to know if there is a function (for the sake of convenience and probably speed) that can calculate the area enclosed by a set of points. It may be a preferred method for image decimation, as it gives moire’-free results. Solution on an image. A good knowledge of Numpy is required to write better optimized code with OpenCV. Learn to find and draw Contours. Mar 10, 2021 · And, as pointed out early, there’s no magic, there must be something in the image evidencing the presence of the film. You can choose another image. ltype specifies the output label image type, an Mar 28, 2016 · Measuring the size of objects with computer vision. The second loops over each of the coordinates in that area. type ()); // all black: mask. 希望のサイズを設定して (例え、 (256,256) )、画像はこのサイズへ変換します。. Setting of params for SimpleBlobDetector in OpenCV 2 is slightly different from OpenCV 3. This is best suited for reducing the size of an image (shrinking). 0-dev. Actually calculating the area of 2D convex hull is pretty easy. Also, the function will most certainly give a wrong results for contours with self-intersections. The picture I'm using as an example is the following one: My objective is to calculate the table's free area (greyish) and the occupied area (orange objects), and so far managed to print the contours with the following code: Contours in OpenCV. 最初にSizeです。. shape,np. RISC-V […] Jan 8, 2013 · template<typename _Tp>class cv::Rect_< _Tp >. OpenCV Python 如何创建HSV颜色空间的颜色条; 如何使用OpenCV Python创建RGB颜色调色盘作为滑动条? 如何使用OpenCV Python在图像上创建水印? 如何在OpenCV Python中裁剪并保存检测到的人脸? 如何使用OpenCV Python检测人脸并在其周围绘制边界框? Sep 29, 2014 · OpenCV and Python versions: This example will run on Python 2. And it’s done! Cropping using OpenCV. The first for loop cycles over each contour area present in the contours list. OpenCV was built to provide a common infrastructure for computer vision applications and accelerate machine perception in products. Cross-Platform. shape[1], 3), np. OpenCV, a powerful open If you dont want to use the openCV classes: Try computing difference of each channel and combine them, try difference of HSV images. Figure 3: Detecting the shape and labeling the color of objects in an image. In order to find the area of the contour in the red circle, you can introduce a check inside the loop if the median points of selected contour falls inside the circle 概要. OpenCV is a highly optimized library with focus on real-time applications. boundingRect(contour) area = rect[2] * rect[3] answered Sep 29, 2017 at 15:07. size()-1] to get the one with the largest area because the contours are sorted in ascending order. Mar 15, 2013 · Here's a visualization for selecting a ROI from an image. We have already seen this in previous chapters. As you can see from that figure to capture the red you need both to include the lower (e. Preferable interpolation methods are cv. We need to create a mask of same size as that of input image, where non-zero pixels corresponds to the area which is to be inpainted. imread('input. I roughly understand linear interpolation, but can only guess what cubic or area do. See the result below. uint8) # draw contours and hull points. Jan 8, 2013 · Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images (represented as Mat 's). I have done in a way of creating 2 convex contours and 2 Mats of zeros and fill them with fillConvexPoly() and doing a bitwise_and() between the two Mats for getting the intersection. arcLength () function. drawContours (mask, [cnt],0,255,-1) pixelpoints = np. contourArea () or from moments, M ['m00']. Of course a convex hull itself is just a contour and therefore we can use OpenCV’s drawContours. static float drawIntersection ( Mat &image, vector<Point> polygon1, vector<Point> polygon2, bool handleNested = true) {. Bug Alert 1: As per the instructions, you can drag a rectangle and then press ENTER and drag another rectangle. C++, Python and Java interfaces support Linux, MacOS, Windows, iOS, and Android. Jan 8, 2013 · Contour area is given by the function cv. May 3, 2020 · contourArea gives area different to pixel count. Jun 12, 2015 · 11. We’ll start with something simple, detecting a red circle on a black background: 6 days ago · Mask and Pixel Points. This is very easy and efficient when using numpy's broadcasting tools. Parameters. Then you can print as shown below. size. zeros (mRgba. 20-dev. imshow("Resized (Width)", resized) Lines 13 and 14 load our input image from disk and display it on our screen: Figure 4: Our original input image for resizing. retval, labels. 4+ and OpenCV 2. Depending on the size of the connected component this is very different. It is also called arc length. A dataset comprising images with embedded text is necessary for understanding the EAST Text Detector. I have a rectangular region in an image and have to calculate the average value. In layman terms, we take a curve and reduce its number of vertices while retaining the bulk of its shape. updated 2013-02-08 14:04:32 -0600. Apr 17, 2015 · On a recent set of images, my OpenCV code stopped finding the correct area of a contour. If you have a list of keypoints. INTER_LINEAR: bilinear interpolation (default) INTER_LINEAR_EXACT. size (), mRgba. drawing = np. The second parameter is the marker id, in this case the marker 23 of the dictionary cv::aruco::DICT_6X6_250. The first argument is the source image, which should be a grayscale image. When a face is obtained, we select the face region alone and search for eyes inside it instead of searching the whole image. 3 days ago · If the pixel value is smaller than the threshold, it is set to 0, otherwise it is set to a maximum value. It can be done as follows: mask = np. rectangle(): cv2. What I am trying to do is basically find the closest blue dot on the minimap and rotate the camera Mar 4, 2020 · Mask and Pixel Points. Oct 11, 2018 · I'm trying to calculate different areas within a picture using opencv's contourArea without much success. detector = cv2. Each rectangle is specified by the center point (mass center), length of each side (represented by Size2f structure) and the rotation angle in degrees. Note that each dictionary is composed of a different number of markers. CV_INTER_CUBIC. transpose (np. Edit: The problem is that there are gaps in the contour. It will contain all the drawings we are going to make (rects and circles). It was developed by John F. for keyPoint in keyPoints: x = keyPoint. addWeighted. i had this question and found another answer here: copy region of interest If we consider (0,0) as top left corner of image called im with left-to-right as x direction and top-to-bottom as y direction. The above formula and code is quick to write and will make changes to brightness and contrast. e. For example, take a look at Figure 4. Opening is just another name of erosion followed by dilation. The usage is shown below. Among all of these contours, I want to find the contours that reside in a specific area I'll define. Canny in. Kharoud. 3. Jul 17, 2014 · I have 2 contours and I want to compare how much the same are they, as the ratio of the area_of_c1/area_of_intersection and area_of_c2/area_of_intersection. INTER_AREA: INTER_AREA uses pixel area relation for resampling. Optimized. Almost all the operations in this section are mainly related to Numpy rather than OpenCV. You can see it better in the image below. Hi, I am using contourArea () to get the area of a binary object. 二つ目の方法は、fxとfyの倍率の方法です。. height of the area. It is useful in removing noise, as we explained above. In the attached example the pixel width is 400 m. Jan 31, 2024 · 1. resize() for this purpose. This takes as input a 2D point set and returns a Box2D structure which contains the following details – (center (x, y), (width, height), angle of rotation). a zero area (m00) for butterfly-shaped Some of the possible interpolation in openCV are: INTER_NEAREST – a nearest-neighbor interpolation; INTER_LINEAR – a bilinear interpolation (used by default) INTER_AREA – resampling using pixel area relation. Edit: Size determines the diameter of the meaningful keypoint neighborhood. Python. Copy area inside contours to another image. There is no specific function for cropping using OpenCV, NumPy array slicing is what does the job. Check the Dec 24, 2021 · OpenCV is pleased to announce a new part of our global computer vision community: OpenCV Area Chairs. But let’s go ahead and take a look at some results. where to find all row and column locations in an array that match a certain condition. net wrapper for OpenCV) can use any one of four interpolation methods: CV_INTER_NN (default) CV_INTER_LINEAR. The function takes the image as input and returns the contours found in the image. png') # call addWeighted function. Here we use the function, cv. 31. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. INTER_AREA: resampling using pixel area relation. Since edge detection is susceptible to noise in the image, first step is to remove the noise in the image with a 5x5 Gaussian filter. Open up a new file, name it object_size. The contourArea() can be applied to find associated areas. contour: The contour input. morphologyEx (img, cv. The results are returned in the structure cv::Moments. 最初に SizeはNoneと設定して、fxとfyのfloatの値に Sep 19, 2015 · The OpenCV library provides a function that returns a set of contours for a binary (thresholded) image. Closing is reverse of Opening, Dilation followed by Erosion. The function rectangle draws a rectangle outline or a filled rectangle. INTER_AREA) cv2. As you can see it’s a cone that makes the minimap slightly brighter on the side it is facing. 0+. Rectangle width and height. png. When resizing an image: Various interpolation techniques come into play to accomplish these operations. The syntax is given below. If you can threshold your red to a binary image then this is easy. MORPH_OPEN, kernel) Result: image. I then draw bounding box around the detected object. INTER_AREA for shrinking and cv. setTo (Scalar. It is capable of (1) running at near real-time at 13 FPS on 720p images and (2) obtains state-of-the-art text detection accuracy. You see, they were working with retinal images (see the top of this post for an example). Aug 20, 2018 · OpenCV’s EAST text detector is a deep learning model, based on a novel architecture and training pattern. Aug 19, 2015 · 71 2 4 9. The same set of arithmetic and comparison operations as for Point_ is available. Jun 24, 2011 · 6. If we have (x1,y1) as the top-left and (x2,y2) as the bottom-right vertex of a ROI, we can use Numpy slicing to crop the image with: Nov 11, 2017 · I have detected these two objects after processing an image. Click Try it button to see the result. Min Area Rect Example <canvas> elements named canvasInput and canvasOutput have been prepared. now you need to make your Activity implement onTouchListener, and implement onTouch, 1st press should be tl corner of the rect, 2nd press br corner The different interpolation techniques used in OpenCV are: INTER_NEAREST: nearest neighbor interpolation technique. One way would be to find area of bounding rectangle. Removing small connected components by area is called area opening. We can find the contours of the given image using the findContours() function of OpenCV, but we have to use a binary or black and white image inside the findContours() function. for contour in contours: rect = cv2. Open Source Computer Vision Finds a rotated rectangle of the minimum area enclosing the input 2D point set. If you want to use existing techniques, try ViBe. Now that we understand the “pixels per metric” ratio, we can implement the Python driver script used to measure the size of objects in an image. 7/Python 3. OpenCV-2. Jul 9, 2023 · I am trying to find the direction the player camera is facing so I can rotate it. Jan 8, 2013 · Prev Tutorial: Creating Bounding boxes and circles for contours Next Tutorial: Image Moments Goal . Oct 6, 2021 · Contour approximation, which uses the Ramer – Douglas – Peucker (RDP) algorithm, aims to simplify a polyline by reducing its vertices given a threshold value. Finally, we visualize the results and save it to disk. height. all (255)); // white square. Mat drawing = Mat::zeros ( canny_output. zeros((thresh. For eye detection in images, first face detection is done over the entire image. CommentedOct 16, 2020 at 19:12. The function cv. In the above code, we loaded an image and converted it to grayscale using the cvtColor() function. In this tutorial you will learn how to: Use the OpenCV function cv::minAreaRect If the pixel value is smaller than the threshold, it is set to 0, otherwise it is set to a maximum value. # create an empty black image. INPAINT_NS. Consider (0,0) as the top-left corner of the image with left-to-right as the x-direction and top-to-bottom as the y-direction. There is a function contourArea you could use. OpenCV is open source and released under the Apache 2 License. Learn to find different properties of contours like Solidity, Mean Intensity etc. In some cases, we may need all the points which comprises that object. Jan 8, 2013 · Access pixel values and modify them. In case of a linear filter, it is a Apr 2, 2019 · The function computes a contour area. 08743619918 128 883. , H=0 to H=10) and upper region (e. For example using scikit-image: import skimage. OpenCV samples contain a sample grabcut. js. resize(image, dim, interpolation=cv2. Tomazi 41 3 8 14. (Few first lines are definition and calculation of convex hull). Contouring is a fundamental technique in computer vision and image processing, playing a crucial role in identifying and extracting object boundaries within an image. Similarly to moments, the area is computed using the Green formula. Jul 31, 2019 · Using OpenCV Python, I'm wondering what would be the best method to identify areas of an image that have a high concentration of pixels of a certain color, and maybe to 'mark' them by plotting a circle around them. Check out the wikipedia page on Image Moments. image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 represents the background label. pt[0] y = keyPoint. width of the area. What is an Area Chair? First and foremost, they are an expert. OpenCV, Python : Find pixels inside a contour. py --image images/simple. morphologyEx () opening = cv. Firstly store rectangular region in another matrix and then you can use meanStdDev to calculate mean value of matrix. Nov 21, 2012 · Then you can access contours[0] to get the contour with the smallest area and contours[contours. Simply specify the height and width (in pixels) of the area to be cropped. To resize an image, scale it along each axis (height and width), considering the specified scale factors or just set the desired height and width. import imageio. Calculates all of the moments up to the third order of a polygon or rasterized shape. 1. We then draw a green circle on each coordinate point, using the circle() function from OpenCV. Using 2 polaroids- one on light source, another one on the camera, it gives chance to measure film thickness, or absence/presence. vector<Point2f> originalPoints; // Your original points. To run our shape detector + color labeler, just download the source code to the post using the form at the bottom of this tutorial and execute the following command: $ python detect_color. pt[1] s = keyPoint. When used for zooming into the image, it uses the INTER_NEAREST method. hpp >. May 25, 2021 · Come, let’s learn about image resizing with OpenCV. I need to calculate the area of a blob/an object in a grayscale picture (loading it as Mat, not as IplImage) using OpenCV. There are multiple ways of doing this. The problem worsens, the smaller the connected component. The second argument is the threshold value which is used to classify the pixel values. Contour Properties. zindarod. 4) sum individual channels and divide them by number of pixels in it ( or with mean function) import numpy as np import cv2 img = cv2. retval. You Need More than cv2. Access image properties. The class includes two members called width and height. jpg',1) cp 4 days ago · OpenCV 4. size (), CV_8UC3 ); For every contour: pick a random color, draw the contour, the bounding rectangle and the minimal enclosing circle with it. Different interpolation methods are used. Nov 3, 2020 · OpenCV provides a function cv2. Keep in mind that even lighting changes will be "any differences, not only human shape or whatever", which might be a problem for very most of all background To find the different features of contours, like area, perimeter, centroid, bounding box etc. img = cv2. imwrite('b. vector<Point2f> ch; // Convex hull points. 2. The sample below demonstrates how to use RotatedRect: Mat test_image (200, 200, CV_8UC3, Scalar (0 Feb 15, 2016 · Color labeling results. In this case, the valid ids go from 0 to 249. The rectangle is small and I would've love to use warpAffine on the rectangle region alone (thus only rotating the pixels therein) but when I allocate the destination image with the size of the rectangle while using the upper-left point of the rectangle to create the transformation matrix then it would return the upper-left corner of the image You can use cv2. 5, (ptA[1] + ptB[1]) * 0. xh qe xn vw nc mz mh ld rq ga