- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我实际上是在尝试使用 ARKit 在 QRCode 上放置一个3D 对象为此,我使用 AVCaptureDevice 来检测 QRCode 并确定 QRCode 的区域,给我一个 CGRect。然后,我对 CGRect 的每个点进行 hitTest 以获得平均 3D 坐标,如下所示:
positionGiven = SCNVector3(0, 0, 0)
for column in Int(qrZone.origin.x)...2*Int(qrZone.origin.x + qrZone.width) {
for row in Int(qrZone.origin.y)...2*Int(qrZone.origin.y + qrZone.height) {
for result in sceneView.hitTest(CGPoint(x: CGFloat(column)/2,y:CGFloat(row)/2), types: [.existingPlaneUsingExtent,.featurePoint]) {
positionGiven.x+=result.worldTransform.columns.3.x
positionGiven.y+=result.worldTransform.columns.3.y
positionGiven.z+=result.worldTransform.columns.3.z
cpts += 1
}
}
}
positionGiven.x=positionGiven.x/cpts
positionGiven.y=positionGiven.y/cpts
positionGiven.z=positionGiven.z/cpts
但 hitTest 未检测到任何结果并卡住相机,而当我通过触摸屏幕进行 hitTest 时,它可以正常工作。你知道为什么它不起作用吗?您有其他想法可以帮助我实现我想做的事情吗?
我已经考虑过使用 CoreMotion 进行 3D 转换,它可以让我倾斜设备,但这看起来真的很乏味。我还听说过 ARWorldAlignmentCamera 可以锁定场景坐标以匹配相机的方向,但我不知道如何使用它!
编辑:我每次触摸屏幕时都会尝试移动我的 3D 对象,并且 hitTest 为正,而且非常准确!我真的不明白为什么像素区域上的 hitTest 不起作用...
编辑 2:这是在屏幕上进行 2-5 次触摸的 hitTest 代码:
@objc func touch(sender : UITapGestureRecognizer) {
for result in sceneView.hitTest(CGPoint(x: sender.location(in: view).x,y: sender.location(in: view).y), types: [.existingPlaneUsingExtent,.featurePoint]) {
//Pop up message for testing
alert("\(sender.location(in: view))", message: "\(result.worldTransform.columns.3)")
//Moving the 3D Object to the new coordinates
let objectList = sceneView.scene.rootNode.childNodes
for object : SCNNode in objectList {
object.removeFromParentNode()
}
addObject(SCNVector3(result.worldTransform.columns.3.x,result.worldTransform.columns.3.y,result.worldTransform.columns.3.z))
}
}
编辑 3 :我设法部分解决了我的问题。
我采用相机的变换矩阵 (session.currentFrame.camera.transform),以便对象位于相机前面。然后,我使用 CGRect 的位置在 (x,y) 上应用平移。但是我无法平移 z 轴,因为我没有足够的信息。我可能需要像 hitTest 那样估计 z 坐标..
提前致谢! :)
最佳答案
你可以使用 Apple's Vision API检测二维码并放置 anchor 。
要开始检测二维码,请使用:
var qrRequests = [VNRequest]()
var detectedDataAnchor: ARAnchor?
var processing = false
func startQrCodeDetection() {
// Create a Barcode Detection Request
let request = VNDetectBarcodesRequest(completionHandler: self.requestHandler)
// Set it to recognize QR code only
request.symbologies = [.QR]
self.qrRequests = [request]
}
在ARSession
的didUpdate Frame
public func session(_ session: ARSession, didUpdate frame: ARFrame) {
DispatchQueue.global(qos: .userInitiated).async {
do {
if self.processing {
return
}
self.processing = true
// Create a request handler using the captured image from the ARFrame
let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: frame.capturedImage,
options: [:])
// Process the request
try imageRequestHandler.perform(self.qrRequests)
} catch {
}
}
}
处理Vision QR请求并触发 HitTest
func requestHandler(request: VNRequest, error: Error?) {
// Get the first result out of the results, if there are any
if let results = request.results, let result = results.first as? VNBarcodeObservation {
guard let payload = result.payloadStringValue else {return}
// Get the bounding box for the bar code and find the center
var rect = result.boundingBox
// Flip coordinates
rect = rect.applying(CGAffineTransform(scaleX: 1, y: -1))
rect = rect.applying(CGAffineTransform(translationX: 0, y: 1))
// Get center
let center = CGPoint(x: rect.midX, y: rect.midY)
DispatchQueue.main.async {
self.hitTestQrCode(center: center)
self.processing = false
}
} else {
self.processing = false
}
}
func hitTestQrCode(center: CGPoint) {
if let hitTestResults = self.latestFrame?.hitTest(center, types: [.featurePoint] ),
let hitTestResult = hitTestResults.first {
if let detectedDataAnchor = self.detectedDataAnchor,
let node = self.sceneView.node(for: detectedDataAnchor) {
let previousQrPosition = node.position
node.transform = SCNMatrix4(hitTestResult.worldTransform)
} else {
// Create an anchor. The node will be created in delegate methods
self.detectedDataAnchor = ARAnchor(transform: hitTestResult.worldTransform)
self.sceneView.session.add(anchor: self.detectedDataAnchor!)
}
}
}
然后在添加 anchor 时处理添加节点。
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
// If this is our anchor, create a node
if self.detectedDataAnchor?.identifier == anchor.identifier {
let sphere = SCNSphere(radius: 1.0)
sphere.firstMaterial?.diffuse.contents = UIColor.redColor()
let sphereNode = SCNNode(geometry: sphere)
sphereNode.transform = SCNMatrix4(anchor.transform)
return sphereNode
}
return nil
}
关于swift - ARKit – 如何在 QRCode 上放置 3D 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45090716/
我想,我使用 qrcode 库成功生成了代码。当我运行该命令时,它不会抛出任何错误。现在如何将文件另存为 .png? 这是我到目前为止的代码: import qrcode qr = qrcode.QR
我要扫描 webView 中的 QR code。 二维码扫描效果好,可以读取数据, 但问题是,扫描后相机屏幕不会关闭。我正在运行一个 dismiss() 函数。 webView 加载 @IBOutle
我正在使用 QRCode api 发现 here 我成功通过Api实现了QRCode生成,但结果是这样的 (我将颜色从白色更改为黄色以提出问题) 所以,现在如果你发现外边界很厚,我希望它变薄.....
(正如 George Stocker 在评论中所建议的,我已经编辑了这个问题,现在它是关于 angular-qrcode 而不是 QRCode.js。) 我正在尝试使用 angular-qrcode在
我正在尝试生成 UTF-8 QRCode,以便可以重新编码重音符号和 Unicode 字符。 为了测试它,我使用了许多解码解决方案: http://zxing.org/w/decode.jspx -
我正在开发一个项目,该项目涉及将图像文件作为桌面上的输入,然后检测和解码存在的所有条形码(一维和二维)。 我一直在使用 zxing,在 GenericMultipleBarcodeReader 的帮助
我正在尝试生成包含多个字符串的 QRCode。它正在工作,但是生成的图像 QRCode 在 imageView 中太小,因此无法读取它(至少我认为这就是为什么我无法从中获取信息的原因)。 它是这样的:
我正在尝试构建一个可以通过扫描二维码来识别用户的应用程序。为此,我想使用主键作为标识符。由于整数的字符长度较短,因此作为二维码不太好看。 所以我的问题是:是否可以将 int 转换为长度超过 10-12
我正在尝试使用 CIDetector 从 UIImage 中检测 QRCode,以便从中提取 messageString。 我有一个基本上接收 UIImage 作为输入并返回解码的 messageSt
我花了很多时间试图诊断这个问题,但我完全卡住了,也许我遗漏了一些非常明显的东西。 已经尝试过: 将返回的图像保存到磁盘以查看它是否正在生成正确地(它是) 添加彩色背景呈现正方形,因此正在加载某些内容
我在 C# 中使用此代码解码(不检测)QRCode,它有效: LuminanceSource ls = new RGBLuminanceSource(image, image.Width, image
同时将 python 库 qrcode==6.1 与 django==3.1.2 集成。我一直在尝试生成一个二维码,其中将包含我其他网站的 URL 链接。 模型.py from django.db i
我想在我的 Laravel 4.1 应用程序中使用二维码生成器。我目前正在选择 https://github.com/endroid/QrCode和 https://github.com/endroi
使用 PHP QrCode 库后,我发现由于某种原因,当使用带有脚本和对话框 (JQuery) 的动态页面时,当我尝试以 .png 格式输出二维码时,我得到了奇怪的符号而不是实际生成的 .png 文件
有人知道一个可以让我在我的应用程序中扫描二维码的好包吗?我不想强制用户下载第三方应用来读取二维码。 最佳答案 我可以推荐react-native-camera用于条形码和二维码扫描 关于react-n
我启动了一个全新的 grails 2.2 应用程序。我想添加 qrcode 插件。 https://plugins.grails.org/plugin/technipelago/qrcode 文档说
使用以下库: qrgen-1.2、zxing-core-1.7 和 zxing-j2se-1.7 我生成了QRCode: ByteArrayOutputStream out = QRCode.
是否有任何免费的在线资源解释如何对这些条形码进行编码? 最佳答案 这个页面应该解释编码算法: https://web.archive.org/web/20100830111303/https://ww
我正在尝试创建一个 JSON 字符串,然后使用 vue-qrcode-component 将其转换为 QRCode。这是我创建字符串的地方: this.qrCode = "{‘type’:’seria
我试图让我的应用程序的用户能够从他们的库中获取图像并扫描其中的 QRCode。相关代码如下: 这是从图像选择器返回所选图像的函数。 func imagePickerController(picker:
我是一名优秀的程序员,十分优秀!