# How to test the line coverage of OpenCV-python

**URL:** <https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217>\
**Category:** Python\
**Created:** [April 9, 2024, 5:17am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217 "2024-04-09T05:17:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bduan](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bduan](https://forum.opencv.org/u/bduan)\
**Post date:** [April 9, 2024, 5:17am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217/1 "2024-04-09T05:17:51Z")

</div>

I write a test file for OpenCV-python, and I want to know the coverage of my test file, but I try to test by coverage.py, which can only test on python interface. I’d like to know how to test the line coverage on OpenCV-python！ Thank you very much

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 9, 2024, 9:28am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217/2 "2024-04-09T09:28:05Z")

</div>

> [@bduan](#):
>
> line coverage on OpenCV-python

please explain, what (you think) that is.

opencv is a c++ library, the python bindings are only shallow, auto-generated wrappers around c++ functionality.

and btw, there are unit tests, performance tests, and even python tests for those wrappers, too, care to take a look at github ?

---

<div class="post-metadata">

**Author:** ![bduan](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bduan](https://forum.opencv.org/u/bduan)\
**Post date:** [April 9, 2024, 9:40am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217/3 "2024-04-09T09:40:28Z")

</div>

can you give me a github website

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 9, 2024, 9:42am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217/4 "2024-04-09T09:42:49Z")

</div>

> **[GitHub - opencv/opencv: Open Source Computer Vision Library](https://github.com/opencv/opencv)**
>
> Open Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [April 9, 2024, 10:21am UTC](https://forum.opencv.org/t/how-to-test-the-line-coverage-of-opencv-python/17217/5 "2024-04-09T10:21:02Z")

</div>

Did you open all this issues?

> <https://github.com/opencv/opencv/issues/25374>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> Op…erating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\calibration.cpp:1483: error: (-211:One of the arguments' values is out of range) The number of points in the view #0 is \< 4 in function 'cvCalibrateCamera2Internal'
> 
> \`\`\`
> 
> as shown above, my input points set 10, but the error told me \<4
> 
> \### Steps to reproduce
> 
> \`\`\`
> import numpy as np
> import cv2
> 
> objectPoints = (np.random.rand( 10, 1, 3) \* 256).astype(np.float32)
> 
> imagePoints = (np.random.rand( 10, 1, 2) \* 256).astype(np.float32)
> 
> imageSize = (5, 5)
> 
> cameraMatrix = None
> 
> distCoeffs = None
> 
> out1, out2, out3, out4, out5 = cv2.calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs)
> 
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25373>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> Op…erating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> as shown here, said the kernel size myst be odd and not larger than 31, I think my input param is expected.
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\imgproc\\src\\deriv.cpp:104: error: (-211:One of the arguments' values is out of range) The kernel size must be odd and not larger than 31 in function 'cv::getSobelKernels'
> 
> \`\`\`
> 
> \### Steps to reproduce
> 
> \`\`\`
> 
> import numpy as np
> import cv2
> 
> 
> src = (np.random.rand(10, 10, 1) \* 256).astype(np.uint8)
> 
> blockSize = 3
> 
> kSize = 3
> 
> borderType = cv2.BORDER\_DEFAULT
> 
> output = cv2.cornerMinEigenVal(src, blockSize, kSize, borderType)
> 
> print(output)
> 
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25370>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> Op…erating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\fundam.cpp:1214: error: (-215:Assertion failed) \_pt1.type() == CV\_64F && \_pt2.type() == CV\_64F && \_F.type() == CV\_64F in function 'cv::sampsonDistance'
> 
> \`\`\`
> all of the input param I set were float64
> 
> \### Steps to reproduce
> 
> \`\`\`
> import numpy as np
> import cv2
> pt1 = (np.random.rand(100, 1, 2)\* 256).astype(np.float64)
> 
> pt2 = (np.random.rand(100, 1, 2)\* 256).astype(np.float64)
> 
> m3 = (np.random.rand(3,3) \* 256).astype(np.float64)
> 
> output = cv2.sampsonDistance(pt1, pt2, m3)
> print(output)
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25367>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> Op…erating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> It will report different crash or bug report, please try it several times!
> 1.
> \`\`\`
> Process finished with exit code -1073740940 (0xC0000374)
> \`\`\`
> 2.
> \`\`\`
> Unknown C++ exception from OpenCV code
> \`\`\`
> 
> of course, it will be successful sometimes, but I meet a lot of times crash or unknown exceoption
> 
> \### Steps to reproduce
> 
> \`\`\`
> import numpy as np
> import cv2
> disparity = (np.random.rand(100, 100, 1) \* 256).astype(np.int16)
> cost = (np.random.rand(100, 100, 1) \* 256).astype(np.int16)
> minDisparity = 3
> numberOfDisparities = 7
> disp12MaxDisp = 1
> 
> output = cv2.validateDisparity(disparity, cost, minDisparity, numberOfDisparities, disp12MaxDisp)
> 
> print(output)
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25366>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> Op…erating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> I checked my input param, I think they are correct. max is 3x3 matrix, pt1 and pt2 is a points set
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\triangulate.cpp:156: error: (-209:Sizes of input arguments do not match) The point-matrices must have one row, and an equal number of columns in function 'icvCorrectMatches'
> 
> \`\`\`
> 
> \### Steps to reproduce
> 
> \`\`\`
> import numpy as np
> import cv2
> 
> max = np.array(\[\[133.28685454, 201.58760058, 126.28483141\],
> \[218.85759196, 214.70814757, 21.50269382\],
> \[151.29091759, 190.73174272, 38.21554576\]\], dtype=np.float32)
> 
> points2 = np.array(\[\[115.73466756, 63.21138927\],
> \[84.3030183 , 225.45245352\],
> \[34.09884804, 98.12981797\]\], dtype=np.float32)
> 
> points3 = np.array(\[\[190.85422998, 55.05627181\],
> \[240.19097166, 206.9696157 \],
> \[186.65860323, 123.41471593\]\], dtype=np.float32)
> 
> newPoints1, newPoints2 = cv2.correctMatches(max, points2, points3)
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25360>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> …Operating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\calibration.cpp:1483: error: (-211:One of the arguments' values is out of range) The number of points in the view #0 is \< 4 in function 'cvCalibrateCamera2Internal'
> \`\`\`
> 
> \### Steps to reproduce
> 
> \`\`\`
> a = np.array(\[\[\[1.7379122 , 151.20229 , 147.24223 \]\],
> 
> \[\[124.7301 , 241.39586 , 103.984085 \]\],
> 
> \[\[123.93298 , 232.07417 , 55.491516 \]\],
> 
> \[\[47.45232 , 69.05811 , 144.78935 \]\],
> 
> \[\[7.1045322 , 84.077644 , 102.39535 \]\]\], dtype=np.float32)
> 
> b = np.array(\[\[\[196.52242 , 245.25883 \]\],
> 
> \[\[166.80057 , 146.80276 \]\],
> 
> \[\[149.4871 , 33.189487 \]\],
> 
> \[\[4.4884953, 155.40897 \]\],
> 
> \[\[223.3596 , 22.199896 \]\]\], dtype=np.float32)
> c = (248, 239)
> 
> d = -1
> 
> e = np.array(\[\[54.709503, 13.623212, 52.287144\],
> \[83.650475, 38.88603 , 143.28778 \],
> \[165.09567 , 174.88637 , 90.716805\]\], dtype=np.float32)
> 
> f = np.array(\[\[0.\],
> \[0.\],
> \[0.\],
> \[0.\],
> \[0.\]\], dtype=np.float32)
> 
> if len(a) \>= 4 and len(b) \>= 4:
> 
> # Example for initCameraMatrix2D, assuming imageSize and other requirements are met
> cameraMatrix = cv2.calibrateCameraROExtended(a, b, c, d, e, f, None, None)
> else:
> print("Insufficient points for operation.")
> 
> \`\`\`
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25359>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> …Operating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> 
> \`\`\`
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\calibration.cpp:1483: error: (-211:One of the arguments' values is out of range) The number of points in the view #0 is \< 4 in function 'cvCalibrateCamera2Internal'
> \`\`\`
> 
> \### Steps to reproduce
> 
> \`\`\`
> a = np.array(\[\[\[1.7379122 , 151.20229 , 147.24223 \]\],
> 
> \[\[124.7301 , 241.39586 , 103.984085 \]\],
> 
> \[\[123.93298 , 232.07417 , 55.491516 \]\],
> 
> \[\[47.45232 , 69.05811 , 144.78935 \]\],
> 
> \[\[7.1045322 , 84.077644 , 102.39535 \]\]\], dtype=np.float32)
> 
> b = np.array(\[\[\[196.52242 , 245.25883 \]\],
> 
> \[\[166.80057 , 146.80276 \]\],
> 
> \[\[149.4871 , 33.189487 \]\],
> 
> \[\[4.4884953, 155.40897 \]\],
> 
> \[\[223.3596 , 22.199896 \]\]\], dtype=np.float32)
> c = (248, 239)
> 
> d = -1
> 
> e = np.array(\[\[54.709503, 13.623212, 52.287144\],
> \[83.650475, 38.88603 , 143.28778 \],
> \[165.09567 , 174.88637 , 90.716805\]\], dtype=np.float32)
> 
> f = np.array(\[\[0.\],
> \[0.\],
> \[0.\],
> \[0.\],
> \[0.\]\], dtype=np.float32)
> 
> if len(a) \>= 4 and len(b) \>= 4:
> 
> # Example for initCameraMatrix2D, assuming imageSize and other requirements are met
> cameraMatrix = cv2.calibrateCameraRO(a, b, c, d, e, f, None, None)
> else:
> print("Insufficient points for operation.")
> \`\`\`
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)

> <https://github.com/opencv/opencv/issues/25358>
>
> \### System Information
> 
> Python version: 3.8.18
> OpenCV python version: 4.9.0
> …Operating System / Platform: Windows-10-10.0.19045-SP0
> 
> \### Detailed description
> \`\`\`
> as shown below, when I invoke cv2.initCameraMatrix2D, I think the input data is compound expectations.
> \`\`\`
> 
> cv2.error: OpenCV(4.9.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\calib3d\\src\\fundam.cpp:385: error: (-28:Unknown error code -28) The input arrays should have at least 4 corresponding point sets to calculate Homography in function 'cv::findHomography'
> 
> 
> \### Steps to reproduce
> 
> \`\`\`
> a = np.array(\[\[\[1.7379122 , 151.20229 , 147.24223 \]\],
> 
> \[\[124.7301 , 241.39586 , 103.984085 \]\],
> 
> \[\[123.93298 , 232.07417 , 55.491516 \]\],
> 
> \[\[47.45232 , 69.05811 , 144.78935 \]\],
> 
> \[\[7.1045322 , 84.077644 , 102.39535 \]\]\], dtype=np.float32)
> 
> b = np.array(\[\[\[196.52242 , 245.25883 \]\],
> 
> \[\[166.80057 , 146.80276 \]\],
> 
> \[\[149.4871 , 33.189487 \]\],
> 
> \[\[4.4884953, 155.40897 \]\],
> 
> \[\[223.3596 , 22.199896 \]\]\], dtype=np.float32)
> c = (1, 1)
> 
> if len(a) \>= 4 and len(b) \>= 4:
> 
> # Example for initCameraMatrix2D, assuming imageSize and other requirements are met
> cameraMatrix = cv2.initCameraMatrix2D(a, b, c)
> else:
> print("Insufficient points for operation.")
> \`\`\`
> 
> \### Issue submission checklist
> 
> \- \[X\] I report the issue, it's not a question
> \- \[X\] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
> \- \[X\] I updated to the latest OpenCV version and the issue is still there
> \- \[X\] There is reproducer code and related data files (videos, images, onnx, etc)
