1 Reply
      Latest reply on Mar 12, 2020 1:03 PM by gchiste
      Angela_m_Li Level 1 Level 1 (0 points)

        I can use the caputreOutput to identify the 3d object, but I do not know how to get the x, y position of the corresponding object.


        Can anybody help?


        I can idenity the object by .identifier but as the time I use .accessibilityActivationPoint.x and .accessibilityActivationPoint.y to detect the x, y position. (Please see the code below) It always come out as 0. And even I move closer or farther the object. The results are always 0.


        How can I detect the x, y position of the captured object?






            func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {

                //       print ("Camera was able to capture a frame:", Date())


                guard let  pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {return}


                guard let model = try? VNCoreMLModel (for: CubeImageClassifier().model) else

                { return }


                let request = VNCoreMLRequest(model:model)


                    (finishedReq,err) in


                    guard let results = finishedReq.results as?

                        [VNClassificationObservation] else {return}


                    guard let firstObservation = results.first else {return}


                    if firstObservation.identifier == "Cube" {

                        print("It is a Cube. Conference = \(firstObservation.confidence)")





                    else { print("NOT Cube")}




                try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request])