I'm trying to convert outputs of mlmodel to UIImage, but it's not working...
outputs of mlmodel : Image(Grayscale width x height)
guard let results = request.results as? [VNPixelBufferObservation] else{ fatalError("Fatal error")}
print(String(describing: type(of: results))
print(String(describing: type(of: results[0])))
let ciImage = CIImage(cvPixelBuffer: results[0].pixelBuffer)
Outputs:
Array<VNPixelBufferObservation>
VNPixelBufferObservation
Error occurs on line 04 :
Thread 1: EXC_BAD_ACCESS (code=1, address=0xe136dbec8)
-------------------------------------------------------------------------------------------
I'm trying to keep mlmodel MultiArray.
outputs of mlmodel : MultiArray (Double 1 x width x height)
guard let results = request.results as? [VNCoreMLFeatureValueObservation] else{ fatalError("Fatal error")}
print(String(describing: type(of: results))
print(String(describing: type(of: results[0]))
print(String(describing: type(of: results[0].featureValue)))
print(results[0].featureValue)
print(results[0].featureValue.multiArrayValue)
let imageMultiArray = results.[0].featureValue.multiArrayValue
let imageData = UnsafeMutablePointer<Double>(OpaquePointer(imageMultiArray?.dataPointer))
let channelStride = imageMultiArray?.strides[0].intValue;
let yStride = imageMultiArray?.strides[1].intValue;
let xStride = imageMultiArray?.strides[2].intValue;
func pixelOffset(_ channel: Int, _ y: Int, _ x: Int) -> Int {
return channel*channelStride! + y*yStride! + x*xStride!
}
let topLeftGreenPixel = Unit8(imageData![pixelOffset(1,0,0)])
Outputs:
Array<VNCoreMLFeatureValueObservation>
VNCoreMLFeatureValueObservation
Optional<MLFeatureValue>
Optional(MultiArray : Double 1 x width x height array)
Optional(Double 1 x width x height array)
Error occurs on line 19 :Use of unresolved identifier 'Unit8
shoud be replaced by Uint8 ? and how to convert to UIImage?
Thank you for your any help in advance!