Comments (1)
We have modified some of your code and now we get the same results in python and c#.
It seems that the error was caused by the CvType of "camera_matrix" and the matrix shape.
The corrected code is below.
Python:
import cv2 as cv
import numpy as np
mtx = np.array ([[ 600.0 , 0.0 , 1280 / 2 ], [ 0.0 , 600.0 , 720 / 2 ], [ 0.0 , 0.0 , 1.0 ]])
dist = np.array ([[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ]])
qrcode_size = 0.176
qrcode_sizes = np . array ([[ 0 , 0 , 0 ], [ 0 , qrcode_size , 0 ], [ qrcode_size , qrcode_size , 0 ], [ qrcode_size, 0 , 0 ]])
points = np.array ([[ 842 , 414 ], [ 544.48657 , 416.01022 ], [ 546.0603 , 121.71874 ], [ 819.1106 , 141.89487 ]])
rvec = np.array ([[ 0.0 , 0.0 , 0.0 ]])
tvec = np.array ([[ 0.0 , 0.0 , 0.0 ]])
succeeded, rvec, tvec = cv.solvePnP ( qrcode_sizes , points , mtx , dist , rvec , tvec )
print ( succeeded ) # returns True
print ( rvec ) # returns [[ 2.19557741] [-2.21423351] [ 0.389877 ]]
print ( tvec ) # returns [[0.12095571] [0.03197572] [0.35943074]]
C#:
float qrSize = 0.176f;
MatOfPoint2f pointsTransformed = new MatOfPoint2f(new Point(842, 414), new Point(544.48657, 416.01022), new Point(546.0603, 121.71874), new Point(819.1106, 141.89487));
MatOfPoint3f objectPoints = new MatOfPoint3f(new Point3(0, 0, 0), new Point3(0, qrSize, 0), new Point3(qrSize, qrSize, 0), new Point3(qrSize, 0, 0));
Mat camera_matrix = new Mat(3, 3, CvType.CV_64FC1);
camera_matrix.put(0, 0, new double[] { 600, 0, 1280 / 2, 0, 600, 720 / 2, 0, 0, 1 });
MatOfDouble camera_distortions = new MatOfDouble(0, 0, 0, 0);
bool succeeded = Calib3d.solvePnP(objectPoints, pointsTransformed, camera_matrix, camera_distortions, rvec, tvec);
Debug.Log(succeeded); // returns True
Debug.Log(rvec.dump()); // returns [2.195577403858928; -2.214233531573715; 0.3898769918731001]
Debug.Log(tvec.dump()); // returns [0.1209557065023445; 0.03197572143545069; 0.3594307467251833]
from opencvforunity.
Related Issues (20)
- How to use ARCamera (Vuforia) with OpenCVForUnity? HOT 3
- Question about commercial use of YOLOv7 sample code HOT 2
- Issue with texture2DToMat HOT 2
- Problem using initUndistortRectifyMap and remap HOT 2
- YOLOv8 support HOT 7
- Camera is very slow to open when using the MSMF VideoCapture backend HOT 2
- GPU Cuda support Windows HOT 2
- Surface Matching contrib sample HOT 4
- YOLOX ONNX Model Dnn.readNet error HOT 1
- OpenCVForUnity.UnityUtils.Utils.renderTextureToMat has memory leak HOT 4
- Facial Expression Recognition is not working in the WebGL Build HOT 1
- can you add DynamicAdaptedFeatureDetector funcation? HOT 1
- Whether "Imgproc.getAffineTransform" method cannot be used HOT 2
- Unable to use FlannBasedMatcher HOT 7
- [2.6.0] fastTexture2DToMat has memory leak HOT 1
- [2.6.0] knnMatch has memory leak HOT 4
- Regarding the opencvforunity.dll dependency issue
- Capture. open (path) in Linux environment, Videoio.CAP_FFMPEG); An error occurred
- How to Utils.matToTexture2D for Float types? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencvforunity.