我试图从我拥有的3x4姿势矩阵中提取3x3旋转矩阵。但是,即使我有一个非常简单的代码设置,另外两个值也不同。我正撞在墙上,因为我不知道为什么会发生这种情况。这是代码:
Camera pose matrix from optical flow homography
5.26354e-315 0 0 0 0 1 0.0078125 0 2 0 0 3
0.0078125 1 0 0 1 1 0 1 2 5.26354e-315 1 3
0 2 0 5.26354e-315 2 1 1.97626e-323 2 2 7.64868e-309 2 3
Creating rotation matrix
5.26354e-315 0 0 0 0 1 0.0078125 0 2
0.0078125 1 0 0 1 1 0 1 2
0 2 0 5.26354e-315 2 1 1.97626e-323 2 2
Rotation matrix
5.26354e-315 0 0 5.26354e-315 0 0 0 0 1 0 0 1 5.26354e-315 0 2 0.0078125 0 2
0.0078125 1 0 0.0078125 1 0 0 1 1 0 1 1 0.0078125 1 2 0 1 2
0 2 0 0 2 0 5.26354e-315 2 1 5.26354e-315 2 1 1.97626e-323 2 2 1.97626e-323 2 2
这是输出:
override func viewDidLoad() {
super.viewDidLoad()
// Get an instance of the AVCaptureDevice class to initialize a device object and provide the video
// as the media type parameter.
let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
// Get an instance of the AVCaptureDeviceInput class using the previous device object.
var error:NSError?
let input: AnyObject! = AVCaptureDeviceInput.deviceInputWithDevice(captureDevice, error: &error)
if (error != nil) {
// If any error occurs, simply log the description of it and don't continue any more.
print("\(error?.localizedDescription)")
return
}
// Initialize the captureSession object.
captureSession = AVCaptureSession()
// Set the input device on the capture session.
captureSession?.addInput(input as! AVCaptureInput)
// Initialize a AVCaptureMetadataOutput object and set it as the output device to the capture session.
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
// Set delegate and use the default dispatch queue to execute the call back
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
captureMetadataOutput.metadataObjectTypes = supportedBarCodes
// Initialize the video preview layer and add it as a sublayer to the viewPreview view's layer.
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewLayer?.frame = view.layer.bounds
view.layer.addSublayer(videoPreviewLayer!)
// Start video capture.
captureSession?.startRunning()
// Move the message label to the top view
view.bringSubviewToFront(messageLabel)
// Initialize QR Code Frame to highlight the QR code
qrCodeFrameView = UIView()
qrCodeFrameView?.layer.borderColor = UIColor.greenColor().CGColor
qrCodeFrameView?.layer.borderWidth = 2
view.addSubview(qrCodeFrameView!)
view.bringSubviewToFront(qrCodeFrameView!)
}
在这里你可以看到我试图将前三列姿势保存到rotvec矩阵中。当我实际设置旋转矩阵等于这三列的姿势时,我得到正确的矩阵,因为第二个矩阵等于第一个矩阵的前三列。但是,当我再次检查旋转矩阵时,(第三个矩阵)它与我在坐标(0,2)和(1,2)上所需的输出不同。 (我在姿势矩阵编号旁边输出了rotvec矩阵编号,你可以在这些坐标处看到数字不匹配)。我不确定为什么会这样,有人可以帮帮我吗?
答案 0 :(得分:0)
解决了我以后遇到这个问题的人的问题:我刚刚将mat类型更改为CV_64F(使其成为双倍)以用于rotvec和pose,并使用全部显示。 berak的信条让我指向了正确的方向。