I am trying to make an augmented reality program in OpenCV. But I always get an error when calling solvePnP.
What I'm trying to do is make an augmented reality program in OpenCV by taking the homography points of the selected cropped image over the entire image and submitting these homography points to solvePnP to get a pose estimate.
I manage to successfully implement homography points, but I cannot get solvePnP to work correctly for some reason. I suspect my inputs are not formatted correctly, but I'm not sure.
If you want to run the code yourself, git clone this (there are files necessary to run it): ( https://github.com/vanstorm9/SLAM-experiments.git )
And run the file: /augmented-reality/sample-scripts/test.py
Can anyone solve this problem?
Error:
Traceback (most recent call last): File "/augmented-reality/sample-scripts/test.py", line 315, in <module> (ret, rvecs, tvecs) = cv2.solvePnP(objp, corners2, mtx, dist) error: /opencv/modules/calib3d/src/solvepnp.cpp:61: error: (-215) npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function solvePnP
solvePnP inputs and size
(42, 3) # objp (143, 2, 1) # corners2 (3, 3) # mtx (1, 5) # dist # objp [[ 0. 0. 0.] [ 1. 0. 0.] [ 2. 0. 0.] [ 3. 0. 0.] [ 4. 0. 0.] [ 5. 0. 0.] [ 6. 0. 0.] [ 0. 1. 0.] [ 1. 1. 0.] [ 2. 1. 0.] [ 3. 1. 0.] [ 4. 1. 0.] [ 5. 1. 0.] [ 6. 1. 0.] [ 0. 2. 0.] [ 1. 2. 0.] [ 2. 2. 0.] [ 3. 2. 0.] [ 4. 2. 0.] [ 5. 2. 0.] [ 6. 2. 0.] [ 0. 3. 0.] [ 1. 3. 0.] [ 2. 3. 0.] [ 3. 3. 0.] [ 4. 3. 0.] [ 5. 3. 0.] [ 6. 3. 0.] [ 0. 4. 0.] [ 1. 4. 0.] [ 2. 4. 0.] [ 3. 4. 0.] [ 4. 4. 0.] [ 5. 4. 0.] [ 6. 4. 0.] [ 0. 5. 0.] [ 1. 5. 0.] [ 2. 5. 0.] [ 3. 5. 0.] [ 4. 5. 0.] [ 5. 5. 0.] [ 6. 5. 0.]] #corners2 [[[ 0.] [ 0.]] [[ 1.] [ 1.]] [[ 2.] [ 2.]] [[ 3.] [ 3.]] [[ 4.] [ 4.]] [[ 5.] [ 5.]] [[ 6.] [ 6.]] [[ 7.] [ 7.]] [[ 8.] [ 8.]] [[ 9.] [ 9.]] [[ 10.] [ 10.]] [[ 11.] [ 11.]] [[ 12.] [ 12.]] [[ 13.] [ 13.]] [[ 14.] [ 14.]] [[ 15.] [ 18.]] [[ 16.] [ 19.]] [[ 17.] [ 20.]] [[ 18.] [ 28.]] [[ 19.] [ 29.]] [[ 20.] [ 30.]] [[ 21.] [ 31.]] [[ 22.] [ 32.]] [[ 23.] [ 33.]] [[ 24.] [ 35.]] [[ 25.] [ 36.]] [[ 26.] [ 39.]] [[ 27.] [ 40.]] [[ 28.] [ 41.]] [[ 29.] [ 42.]] [[ 31.] [ 52.]] [[ 32.] [ 53.]] [[ 33.] [ 54.]] [[ 34.] [ 56.]] [[ 35.] [ 57.]] [[ 36.] [ 59.]] [[ 37.] [ 60.]] [[ 38.] [ 61.]] [[ 40.] [ 69.]] [[ 41.] [ 70.]] [[ 42.] [ 71.]] [[ 43.] [ 72.]] [[ 44.] [ 75.]] [[ 45.] [ 76.]] [[ 47.] [ 78.]] [[ 49.] [ 79.]] [[ 50.] [ 86.]] [[ 51.] [ 87.]] [[ 52.] [ 88.]] [[ 53.] [ 89.]] [[ 54.] [ 90.]] [[ 55.] [ 94.]] [[ 48.] [ 95.]] [[ 56.] [ 101.]] [[ 42.] [ 105.]] [[ 61.] [ 109.]] [[ 62.] [ 110.]] [[ 57.] [ 111.]] [[ 58.] [ 112.]] [[ 61.] [ 113.]] [[ 59.] [ 115.]] [[ 58.] [ 116.]] [[ 63.] [ 117.]] [[ 60.] [ 118.]] [[ 70.] [ 119.]] [[ 71.] [ 120.]] [[ 74.] [ 125.]] [[ 75.] [ 126.]] [[ 76.] [ 128.]] [[ 77.] [ 129.]] [[ 78.] [ 131.]] [[ 66.] [ 133.]] [[ 67.] [ 134.]] [[ 69.] [ 135.]] [[ 79.] [ 136.]] [[ 72.] [ 137.]] [[ 80.] [ 139.]] [[ 73.] [ 140.]] [[ 83.] [ 141.]] [[ 82.] [ 142.]] [[ 91.] [ 143.]] [[ 92.] [ 144.]] [[ 93.] [ 145.]] [[ 94.] [ 146.]] [[ 85.] [ 147.]] [[ 86.] [ 148.]] [[ 87.] [ 149.]] [[ 95.] [ 150.]] [[ 101.] [ 153.]] [[ 102.] [ 154.]] [[ 103.] [ 155.]] [[ 104.] [ 156.]] [[ 105.] [ 157.]] [[ 106.] [ 158.]] [[ 107.] [ 159.]] [[ 108.] [ 160.]] [[ 109.] [ 161.]] [[ 110.] [ 163.]] [[ 111.] [ 164.]] [[ 112.] [ 165.]] [[ 113.] [ 166.]] [[ 114.] [ 167.]] [[ 99.] [ 168.]] [[ 100.] [ 169.]] [[ 118.] [ 171.]] [[ 119.] [ 172.]] [[ 120.] [ 173.]] [[ 121.] [ 174.]] [[ 122.] [ 175.]] [[ 123.] [ 176.]] [[ 102.] [ 177.]] [[ 103.] [ 178.]] [[ 106.] [ 180.]] [[ 107.] [ 181.]] [[ 124.] [ 182.]] [[ 115.] [ 183.]] [[ 116.] [ 184.]] [[ 117.] [ 187.]] [[ 150.] [ 188.]] [[ 128.] [ 192.]] [[ 127.] [ 194.]] [[ 129.] [ 197.]] [[ 130.] [ 198.]] [[ 131.] [ 199.]] [[ 135.] [ 200.]] [[ 136.] [ 201.]] [[ 137.] [ 202.]] [[ 138.] [ 203.]] [[ 134.] [ 204.]] [[ 113.] [ 205.]] [[ 141.] [ 206.]] [[ 142.] [ 207.]] [[ 145.] [ 208.]] [[ 143.] [ 212.]] [[ 144.] [ 213.]] [[ 149.] [ 214.]] [[ 157.] [ 216.]] [[ 159.] [ 218.]] [[ 131.] [ 220.]] [[ 112.] [ 221.]] [[ 163.] [ 223.]] [[ 164.] [ 224.]] [[ 157.] [ 228.]]]
code
#!/usr/bin/python
source share