# Python

**URL:** https://forum.opencv.org/c/python/7.md?page=3

[Latest](https://forum.opencv.org/latest.md) · [Categories](https://forum.opencv.org/categories.md) · [Tags](https://forum.opencv.org/tags.md)

**Page:** 4

---

## [How to detect Scanned Document Edges and Cropping it in Python?](https://forum.opencv.org/t/how-to-detect-scanned-document-edges-and-cropping-it-in-python/22670)

<div class="topic-metadata">

**Author:** [@emadyounan](https://forum.opencv.org/u/emadyounan)\
**Replies:** 2\
**Last updated:** [June 24, 2025, 7:59pm UTC](https://forum.opencv.org/t/how-to-detect-scanned-document-edges-and-cropping-it-in-python/22670 "2025-06-24T19:59:47Z")

</div>

I have hard, messy Scanned Images with a noisy background as below I tried this code, but didn’t get the contours. image = cv2.imread(r'Images\\2.png') orig = image.copy() gray = cv2.cvtColor(image, cv2.COLOR\_BGR2GRA…

---

## [Gstreamer Error](https://forum.opencv.org/t/gstreamer-error/22675)

<div class="topic-metadata">

**Author:** [@engineer](https://forum.opencv.org/u/engineer)\
**Replies:** 1\
**Last updated:** [June 24, 2025, 7:15pm UTC](https://forum.opencv.org/t/gstreamer-error/22675 "2025-06-24T19:15:13Z")

</div>

Hi. When i run “cv2.getbuildinformation()” in python, gstreamer shows “yes”. But when i run this commandat the below in pycharm,it gives No Module CV2 error gst\_pipeline = ( "udpsrc port=5000 caps=application/x-rtp,…

---

## [Photonic Chip Image Recognition](https://forum.opencv.org/t/photonic-chip-image-recognition/22540)

<div class="topic-metadata">

**Author:** [@R.W.V](https://forum.opencv.org/u/R.W.V)\
**Replies:** 6\
**Last updated:** [June 23, 2025, 8:55pm UTC](https://forum.opencv.org/t/photonic-chip-image-recognition/22540 "2025-06-23T20:55:30Z")

</div>

I have photos of these photonic chips (top left) for which I need to create and overlay highlighting its shape. I dont get the full chip in the image, only a corner. I have tried using Canny and HoughlinesP to recognize …

---

## [How to reset the covariance matrix in kalman filter](https://forum.opencv.org/t/how-to-reset-the-covariance-matrix-in-kalman-filter/22633)

<div class="topic-metadata">

**Author:** [@CURSO\_EE\_1S\_2024](https://forum.opencv.org/u/CURSO_EE_1S_2024)\
**Replies:** 0\
**Last updated:** [June 22, 2025, 11:38pm UTC](https://forum.opencv.org/t/how-to-reset-the-covariance-matrix-in-kalman-filter/22633 "2025-06-22T23:38:35Z")

</div>

I am simulating a system in which I do not have very accurate information about the measurement and process noises (R and Q). However, although my linear Kalman filter works, it seems that there is some error, since at t…

---

## [How to use MapperGradEuclid](https://forum.opencv.org/t/how-to-use-mappergradeuclid/22523)

<div class="topic-metadata">

**Author:** [@Steve\_Best](https://forum.opencv.org/u/Steve_Best)\
**Replies:** 3\
**Last updated:** [June 18, 2025, 2:02pm UTC](https://forum.opencv.org/t/how-to-use-mappergradeuclid/22523 "2025-06-18T14:02:48Z")

</div>

I’ve seen a function MapperGradEuclid and I’d like to see if it is useful, but, despite it being in the docs I can’t seem to access it from python. I’ve seen some StackOverflow questions, none very recent, where people …

---

## [How do I know which coordinates go to which coordinates in the warped image?](https://forum.opencv.org/t/how-do-i-know-which-coordinates-go-to-which-coordinates-in-the-warped-image/22242)

<div class="topic-metadata">

**Author:** [@JeongHo\_Ju](https://forum.opencv.org/u/JeongHo_Ju)\
**Replies:** 0\
**Last updated:** [June 12, 2025, 3:53am UTC](https://forum.opencv.org/t/how-do-i-know-which-coordinates-go-to-which-coordinates-in-the-warped-image/22242 "2025-06-12T03:53:53Z")

</div>

Based on the code below, I transformed the image, found which coordinates in the warped image were shifted to which coordinates in the warped image, and drew a Bounding Box. However, the Bounding Box is not being drawn c…

---

## [initUndistortRectifyMap does not return same undistorted image as manual undistortion](https://forum.opencv.org/t/initundistortrectifymap-does-not-return-same-undistorted-image-as-manual-undistortion/21117)

<div class="topic-metadata">

**Author:** [@zeellos](https://forum.opencv.org/u/zeellos)\
**Replies:** 3\
**Last updated:** [May 31, 2025, 6:10am UTC](https://forum.opencv.org/t/initundistortrectifymap-does-not-return-same-undistorted-image-as-manual-undistortion/21117 "2025-05-31T06:10:04Z")

</div>

I have been trying to replicate what initUndistortRectifyMap does for my application. For some reason, when I do manual undistortion, I get different result than using initUndistortRectifyMap. I feel I am following the …

---

## [Can you explain values of imgIdx and trainIdx in this example of cv.match?](https://forum.opencv.org/t/can-you-explain-values-of-imgidx-and-trainidx-in-this-example-of-cv-match/21018)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://forum.opencv.org/u/pauljurczak)\
**Replies:** 1\
**Last updated:** [May 30, 2025, 4:03am UTC](https://forum.opencv.org/t/can-you-explain-values-of-imgidx-and-trainidx-in-this-example-of-cv-match/21018 "2025-05-30T04:03:59Z")

</div>

This OpenCV Python script: import numpy as np, cv2 as cv bf = cv.BFMatcher(cv.NORM\_L1, crossCheck=False) bf.add(np.array(\[\[0\], \[1\], \[2\]\], dtype='f4')) # train image 0 bf.add(np.array(\[\[0.1\], \[1.1\], \[2.1\]\], dtype='f4')…

---

## [Python bindings question](https://forum.opencv.org/t/python-bindings-question/21114)

<div class="topic-metadata">

**Author:** [@Leonor\_Francisco](https://forum.opencv.org/u/Leonor_Francisco)\
**Replies:** 1\
**Last updated:** [May 29, 2025, 9:47pm UTC](https://forum.opencv.org/t/python-bindings-question/21114 "2025-05-29T21:47:13Z")

</div>

Hello everyone, I need to add a C++ “proxy” class in OpenCV that will: Internally call methods defined by the Python user. Externally expose methods that the Python user can call. I’m torn between two options: Imple…

---

## [Add text or image without desktop environment (RPi and Picamera2)](https://forum.opencv.org/t/add-text-or-image-without-desktop-environment-rpi-and-picamera2/21103)

<div class="topic-metadata">

**Author:** [@GG2GG](https://forum.opencv.org/u/GG2GG)\
**Replies:** 2\
**Last updated:** [May 28, 2025, 9:35am UTC](https://forum.opencv.org/t/add-text-or-image-without-desktop-environment-rpi-and-picamera2/21103 "2025-05-28T09:35:57Z")

</div>

Hi all, I’m new here and newbie. I’m working on Raspberry with attached camera and Picamera2. The RPi is running Bookworm Lite without desktop. I got a 640\*480 preview on a 800\*480 DSI LCD display connected to RP1, so th…

---

## [How to automatically detect video start timestamp from in OpenCV](https://forum.opencv.org/t/how-to-automatically-detect-video-start-timestamp-from-in-opencv/21099)

<div class="topic-metadata">

**Author:** [@Zaid\_Siddiqui](https://forum.opencv.org/u/Zaid_Siddiqui)\
**Replies:** 0\
**Last updated:** [May 27, 2025, 7:18am UTC](https://forum.opencv.org/t/how-to-automatically-detect-video-start-timestamp-from-in-opencv/21099 "2025-05-27T07:18:16Z")

</div>

Hi everyone, in the below given code I want to automate the video\_start\_time to capture the start time directly from the first frame of the video and I am unable to do it. import cv2 import os from datetime import dat…

---

## [G-API: Python C API symbols not recognized during compilation](https://forum.opencv.org/t/g-api-python-c-api-symbols-not-recognized-during-compilation/21087)

<div class="topic-metadata">

**Author:** [@Rita\_Melo](https://forum.opencv.org/u/Rita_Melo)\
**Replies:** 0\
**Last updated:** [May 24, 2025, 9:52pm UTC](https://forum.opencv.org/t/g-api-python-c-api-symbols-not-recognized-during-compilation/21087 "2025-05-24T21:52:42Z")

</div>

Hi! I’m implementing a C++ class in G-API that needs to call methods defined in a Python object (using ‘PyObject\_CallMethod’, ‘Py\_XDECREF’, PyGILState etc.). However, during compilation I get errors like: ‘PyObject’ d…

---

## [Videocapture set framenumber gives a None frame (not always)](https://forum.opencv.org/t/videocapture-set-framenumber-gives-a-none-frame-not-always/21053)

<div class="topic-metadata">

**Author:** [@Ramesh\_Nuthalapati](https://forum.opencv.org/u/Ramesh_Nuthalapati)\
**Replies:** 7\
**Last updated:** [May 23, 2025, 2:35pm UTC](https://forum.opencv.org/t/videocapture-set-framenumber-gives-a-none-frame-not-always/21053 "2025-05-23T14:35:03Z")

</div>

I’m using a simple python code to extract thumbnail from a video. Using opencv headless version 4.6.0.66 as AWS lambda layer AWS Lambda has 10240MB memory and 1024MB Ephemeral storage. Runtime is Python 3.9 Architect…

---

## [Error: OpenCV(4.11.0) 👎 error: (-5:Bad argument) in function 'imshow'](https://forum.opencv.org/t/error-opencv-4-11-0-error-5-bad-argument-in-function-imshow/20741)

<div class="topic-metadata">

**Author:** [@ACG](https://forum.opencv.org/u/ACG)\
**Replies:** 6\
**Last updated:** [May 22, 2025, 12:19pm UTC](https://forum.opencv.org/t/error-opencv-4-11-0-error-5-bad-argument-in-function-imshow/20741 "2025-05-22T12:19:26Z")

</div>

I’m interested in image processing with python. I use macbook air M2 macos sequoia 15.4. I’m developing python code on anaconda spyder ide. I keep getting the following error: error: OpenCV(4.11.0) :-1: error: (-5:Bad a…

---

## [cv2.findContours fails to detect black rectangle aligned with x-axis](https://forum.opencv.org/t/cv2-findcontours-fails-to-detect-black-rectangle-aligned-with-x-axis/20995)

<div class="topic-metadata">

**Author:** [@Sroc](https://forum.opencv.org/u/Sroc)\
**Replies:** 4\
**Last updated:** [May 16, 2025, 5:35pm UTC](https://forum.opencv.org/t/cv2-findcontours-fails-to-detect-black-rectangle-aligned-with-x-axis/20995 "2025-05-16T17:35:36Z")

</div>

Hi everyone I’m working with OpenCV in Python to detect a large black rectangle in an image. Everything works fine when the rectangle is rotated at an angle, but when it’s aligned exactly with the x-axis (i.e., perfectl…

---

## [Obtain 2D coordinate system from a top-down view](https://forum.opencv.org/t/obtain-2d-coordinate-system-from-a-top-down-view/21025)

<div class="topic-metadata">

**Author:** [@andrew\_leda](https://forum.opencv.org/u/andrew_leda)\
**Replies:** 0\
**Last updated:** [May 15, 2025, 1:21pm UTC](https://forum.opencv.org/t/obtain-2d-coordinate-system-from-a-top-down-view/21025 "2025-05-15T13:21:57Z")

</div>

Hello, I am trying to obtain an accurate 2D coordinate system from captured images. For now I am using a simulator where I have a perspective vision sensor perpendicular with the ground. To that goal, I did camera cali…

---

## [An improved template matching with rotation and scale invariant](https://forum.opencv.org/t/an-improved-template-matching-with-rotation-and-scale-invariant/5566)

<div class="topic-metadata">

**Author:** [@cozzyde](https://forum.opencv.org/u/cozzyde)\
**Replies:** 5\
**Last updated:** [May 12, 2025, 12:52am UTC](https://forum.opencv.org/t/an-improved-template-matching-with-rotation-and-scale-invariant/5566 "2025-05-12T00:52:18Z")

</div>

While I was doing the robotic grasping research, I found out that template matching is a good approach for quick object localization but the template matching provided by OpenCV was not able to detect rotated and scaled …

---

## [Slow line rendering under certain corner cases](https://forum.opencv.org/t/slow-line-rendering-under-certain-corner-cases/20977)

<div class="topic-metadata">

**Author:** [@CarlosRDomin](https://forum.opencv.org/u/CarlosRDomin)\
**Replies:** 1\
**Last updated:** [May 8, 2025, 6:11pm UTC](https://forum.opencv.org/t/slow-line-rendering-under-certain-corner-cases/20977 "2025-05-08T18:11:13Z")

</div>

I’ve noticed that drawing certain lines with particular thickness values takes several seconds, whereas almost any other combination of line endpoints or thickness take sub 3ms. Minimum reproducible example: import cv2 …

---

## [Python YUNet workflow](https://forum.opencv.org/t/python-yunet-workflow/20942)

<div class="topic-metadata">

**Author:** [@TypeVar](https://forum.opencv.org/u/TypeVar)\
**Replies:** 0\
**Last updated:** [May 3, 2025, 6:47am UTC](https://forum.opencv.org/t/python-yunet-workflow/20942 "2025-05-03T06:47:14Z")

</div>

Hi there. I’m enjoying YUNet face detector from here: opencv\_zoo/models/face\_detection\_yunet at main · opencv/opencv\_zoo · GitHub I noticed that raw .onnx file has input shape of 640x640, but in demo.py the input shape…

---

## [Mybe bug in OpenCV algorithm for method cv2.erode()](https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921)

<div class="topic-metadata">

**Author:** [@jamilalidrus](https://forum.opencv.org/u/jamilalidrus)\
**Replies:** 1\
**Last updated:** [April 29, 2025, 11:23pm UTC](https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921 "2025-04-29T23:23:13Z")

</div>

Hello Guys i found something anomaly in openCV for method cv2.erode() i have matrix 4x4 like this \[1,0,0,0\], \[1,1,1,0\], \[1,1,1,0\], \[0,1,1,0\], with Kernel = \[0,1,0\], \[1,1,1\], \[0,1,0\], when i am try to calculate usi…

---

## [Module 'cv2' has no attribute TPS transformer creator (Google Colab)](https://forum.opencv.org/t/module-cv2-has-no-attribute-tps-transformer-creator-google-colab/20912)

<div class="topic-metadata">

**Author:** [@Aniket\_Chakraborty1](https://forum.opencv.org/u/Aniket_Chakraborty1)\
**Replies:** 0\
**Last updated:** [April 28, 2025, 8:09am UTC](https://forum.opencv.org/t/module-cv2-has-no-attribute-tps-transformer-creator-google-colab/20912 "2025-04-28T08:09:04Z")

</div>

I am using the TPS method for image warping. I am using the OpenCV version 4.11.0.86. In my first run, all the codes works good and gives me my required output. Then, i was using the function cv2.createThinPlateSplineSha…

---

## [Stitching Long Grayscale Images with Fixed Lateral Overlap and Unknown Vertical Displacement in OpenCV](https://forum.opencv.org/t/stitching-long-grayscale-images-with-fixed-lateral-overlap-and-unknown-vertical-displacement-in-opencv/20903)

<div class="topic-metadata">

**Author:** [@glir](https://forum.opencv.org/u/glir)\
**Replies:** 1\
**Last updated:** [April 27, 2025, 11:22am UTC](https://forum.opencv.org/t/stitching-long-grayscale-images-with-fixed-lateral-overlap-and-unknown-vertical-displacement-in-opencv/20903 "2025-04-27T11:22:07Z")

</div>

Hello everyone, I would like to ask if there is any OpenCV function or method suitable for correctly stitching together very long and narrow grayscale images with the following characteristics: 16-bit grayscale images …

---

## [Unable to compile CUDA Version](https://forum.opencv.org/t/unable-to-compile-cuda-version/20888)

<div class="topic-metadata">

**Author:** [@Fellipe\_Zambrano](https://forum.opencv.org/u/Fellipe_Zambrano)\
**Replies:** 7\
**Last updated:** [April 27, 2025, 5:03am UTC](https://forum.opencv.org/t/unable-to-compile-cuda-version/20888 "2025-04-27T05:03:56Z")

</div>

Hello guys. I’m during 3 days trying to make opencv to work with CUDA. I already have CUDA installed, cudnn etc. What happens: After making all process described in some youtube videos, many and many times, with lots o…

---

## [Using OpenCV calib to Project 3D Points onto my 2D Camera Output](https://forum.opencv.org/t/using-opencv-calib-to-project-3d-points-onto-my-2d-camera-output/19754)

<div class="topic-metadata">

**Author:** [@Verano](https://forum.opencv.org/u/Verano)\
**Replies:** 1\
**Last updated:** [April 22, 2025, 8:26am UTC](https://forum.opencv.org/t/using-opencv-calib-to-project-3d-points-onto-my-2d-camera-output/19754 "2025-04-22T08:26:27Z")

</div>

Hey y´all, I´m pretty new to this and spend an hour searching this Forum to get an example for what I´m trying to do, but I found nothing similar, so… My plan is to project a point cloud output of a mmwave radar system…

---

## [Cannot get FOURCC with CAP\_MSMF as backend](https://forum.opencv.org/t/cannot-get-fourcc-with-cap-msmf-as-backend/20858)

<div class="topic-metadata">

**Author:** [@Hanning\_Liu](https://forum.opencv.org/u/Hanning_Liu)\
**Replies:** 0\
**Last updated:** [April 21, 2025, 9:56am UTC](https://forum.opencv.org/t/cannot-get-fourcc-with-cap-msmf-as-backend/20858 "2025-04-21T09:56:34Z")

</div>

I’m new to programming. I want to see the RAW format of my laptop camera. So I am trying to use the python script below to print out the format, but I cannot get result with CAP\_MSMF as backend. I think the code 22 (w…

---

## [How to differentiate a live person infront of Web Cam to a Photo of person](https://forum.opencv.org/t/how-to-differentiate-a-live-person-infront-of-web-cam-to-a-photo-of-person/9365)

<div class="topic-metadata">

**Author:** [@Varsha](https://forum.opencv.org/u/Varsha)\
**Replies:** 1\
**Last updated:** [April 17, 2025, 3:00pm UTC](https://forum.opencv.org/t/how-to-differentiate-a-live-person-infront-of-web-cam-to-a-photo-of-person/9365 "2025-04-17T15:00:29Z")

</div>

For an attendance project, How can I differentiate Live person infront of web cam to showing a photo of the person. How do we do that? Any ideas is appreciated

---

## [Fisheye Stereo ChAruco calibration](https://forum.opencv.org/t/fisheye-stereo-charuco-calibration/20563)

<div class="topic-metadata">

**Author:** [@room2](https://forum.opencv.org/u/room2)\
**Replies:** 2\
**Last updated:** [April 17, 2025, 8:15am UTC](https://forum.opencv.org/t/fisheye-stereo-charuco-calibration/20563 "2025-04-17T08:15:49Z")

</div>

Hello, I am attempting to calibrate a wide angle lens stereo camera (125º) with the method in the title, but I am not able to make the code work. My initial attempt was to use a normal chessboard to obtain the calibrati…

---

## [How to build a custom version of opencv compatible with CUDA and python 3.7](https://forum.opencv.org/t/how-to-build-a-custom-version-of-opencv-compatible-with-cuda-and-python-3-7/20752)

<div class="topic-metadata">

**Author:** [@bhattarai333](https://forum.opencv.org/u/bhattarai333)\
**Replies:** 1\
**Last updated:** [April 15, 2025, 1:36pm UTC](https://forum.opencv.org/t/how-to-build-a-custom-version-of-opencv-compatible-with-cuda-and-python-3-7/20752 "2025-04-15T13:36:46Z")

</div>

I have a hard requirement of python3.7 for certain libraries (aeneas & afaligner). I’ve been using the regular opencv-python and ffmpeg libraries in my program and they’ve been working find. Recently I wanted to adjust …

---

## [Bad conversion to jpg from 16UC1 image or jpg compression artifacts?](https://forum.opencv.org/t/bad-conversion-to-jpg-from-16uc1-image-or-jpg-compression-artifacts/20737)

<div class="topic-metadata">

**Author:** [@galou](https://forum.opencv.org/u/galou)\
**Replies:** 11\
**Last updated:** [April 11, 2025, 9:41am UTC](https://forum.opencv.org/t/bad-conversion-to-jpg-from-16uc1-image-or-jpg-compression-artifacts/20737 "2025-04-11T09:41:22Z")

</div>

I use 16UC1 images in the context of depth cameras that produce a monochrome depth image, where typically an intensity of 1 represents a distance of 1 mm. This small script generates a correct PNG image but incorrect JP…

---

## [How to use opacity in drawKeypoints or drawMatches?](https://forum.opencv.org/t/how-to-use-opacity-in-drawkeypoints-or-drawmatches/20792)

<div class="topic-metadata">

**Author:** [@dustinfreeman](https://forum.opencv.org/u/dustinfreeman)\
**Replies:** 1\
**Last updated:** [April 10, 2025, 8:51pm UTC](https://forum.opencv.org/t/how-to-use-opacity-in-drawkeypoints-or-drawmatches/20792 "2025-04-10T20:51:08Z")

</div>

I’m using OpenCV 4.10 in python, but this should generalize to anyone using drawKeypoints or drawMatches. I want to draw the keypoints with less than 100% opacity over the image. I have tried: img3 = cv2.drawKeypoints(i…

[Previous page](https://forum.opencv.org/c/python/7.md?page=2)

[Next page](https://forum.opencv.org/c/python/7.md?page=4)
