如何使下面的代码检测部分透明的图像?

时间:2019-06-04 21:18:40

标签: swift xcode object-detection arkit

我正在创建一个增强现实应用程序,该应用程序可以检测对象并在检测到对象后弹出标签。我正在尝试让程序识别一个窗口,但是,由于户外活动不断变化,因此永远不会正确检测到上传到Assets.xcassets的图像。因此,我使窗口的窗口部分透明。本质上,我希望摄像机检测到窗户玻璃以外的所有东西(窗玻璃,部分墙壁,背景等)。我不确定如何真正执行此操作以及如何执行此操作。

从概念上讲,我认为我可以以某种方式使程序能够识别窗口的透明部分并忽略它们。因此,当将输入到Assets.xcassets中的图像与实际窗口进行比较时,该程序将忽略玻璃窗,仅检测图像中的所有其他内容。

import UIKit
import ARKit

class ViewController: UIViewController {

    /// Primary SceneKit view that renders the AR session
    @IBOutlet var sceneView: ARSCNView!

    /// A serial queue for thread safety when modifying SceneKit's scene graph.
    let updateQueue = DispatchQueue(label: "\(Bundle.main.bundleIdentifier!).serialSCNQueue")

    // MARK: - Lifecycle

    // Called after the controller's view is loaded into memory.
    override func viewDidLoad() {
        super.viewDidLoad()

        // Set the view's delegate
        sceneView.delegate = self

        // Show statistics such as FPS and timing information (useful during development)
        sceneView.showsStatistics = true

        // Enable environment-based lighting
        sceneView.autoenablesDefaultLighting = true
        sceneView.automaticallyUpdatesLighting = true
    }

    // Notifies the view controller that its view is about to be added to a view hierarchy.
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        guard let refImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: Bundle.main) else {
                fatalError("Missing expected asset catalog resources.")
        }

        // Create a session configuration
        let configuration = ARImageTrackingConfiguration()
        configuration.trackingImages = refImages
        configuration.maximumNumberOfTrackedImages = 1

        // Run the view's session
        sceneView.session.run(configuration, options: ARSession.RunOptions(arrayLiteral: [.resetTracking, .removeExistingAnchors]))
    }

    // Notifies the view controller that its view is about to be removed from a view hierarchy.
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        // Pause the view's session
        sceneView.session.pause()
    }

}

我希望能够检测到窗口图像。

0 个答案:

没有答案