Hey, I am natively an ML Engineer so not really well versed in swift.
I am currently trying to use a model of mine in a swift app. The model detects knives and has an input size of 640x640.
i have set up AV capture and that works well I can just see the camera on my screen. I have also set up the coreML model and it also works and detects the objects.
so what doesnt work is the way I draw boxes around the object. e.g. the objects box params are Raw model output: x=342.25, y=293.0, w=105.375, h=150.5 when Im in the middle of the screen. seems ok for me, I want to draw a box now with these params. But the CGRect object is really weird to me, firstly the x value is the y value in the box (i notice this because when I move the object up and down , the x val will change but not the y val). then if I just switch the values, the drawn box will move ok in the y direction but mirrored in the x direction.
what things need to be considered/changed here, is it something about the layer setup? See my implementation here: func setupLayers() { previewLayer = AVCaptureVideoPreviewLayer(session: session) previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill rootLayer = previewView.layer previewLayer.frame = rootLayer.bounds rootLayer.addSublayer(previewLayer)
inferenceTimeBounds = CGRect(x: rootLayer.frame.midX-75, y: rootLayer.frame.maxY-70, width: 150, height: 17)
inferenceTimeLayer = createRectLayer(inferenceTimeBounds, [1,1,1,1])
inferenceTimeLayer.cornerRadius = 7
rootLayer.addSublayer(inferenceTimeLayer)
detectionLayer = CALayer()
detectionLayer.frame = rootLayer.bounds
detectionLayer.position = CGPoint(x: rootLayer.bounds.midX, y: rootLayer.bounds.midY)
rootLayer.addSublayer(detectionLayer)
}