我尝试使用https://developer.apple.com/documentation/coreimage/ciimageprocessorkernel的示例代码对手机摄像头拍摄的图像进行二值化,即:
首先将CIImageProcessorKernel
子类化为:
class ThresholdImageProcessorKernel: CIImageProcessorKernel {
static let device = MTLCreateSystemDefaultDevice()
override class func process(with inputs: [CIImageProcessorInput]?, arguments: [String : Any]?, output: CIImageProcessorOutput) throws {
guard
let device = device,
let commandBuffer = output.metalCommandBuffer,
let input = inputs?.first,
let sourceTexture = input.metalTexture,
let destinationTexture = output.metalTexture,
let thresholdValue = arguments?["thresholdValue"] as? Float else {
return
}
let threshold = MPSImageThresholdBinary(
device: device,
thresholdValue: thresholdValue,
maximumValue: 1.0,
linearGrayColorTransform: nil)
threshold.encode(
commandBuffer: commandBuffer,
sourceTexture: sourceTexture,
destinationTexture: destinationTexture)
}
}
然后将其用作(开发者页面中的拼写错误,ThresholdImageProcessorKernel
处缺少 r ):
let result = try? ThresholdImageProcessorKernel.apply(
withExtent: inputImage.extent,
inputs: [inputImage],
arguments: ["thresholdValue": 0.25])
结果是全白图像?
答案 0 :(得分:0)
你需要:
答案 1 :(得分:0)
请务必覆盖public canLeave: boolean = false; //this'll controll if the user can leave the page or not
public userType: string = 'user'; // just setting a default value to your select
// this is a navguard
ionViewCanLeave() {
if(!this.canLeave){
if(this.userType == 'user'){
this.canLeave = true; // you'll need to set canLeave to true so when setting the rootpage it doesn't enters the if statemente again
this.navCtrl.setRoot('UserPage');
} else {
this.canLeave = true;
this.navCtrl.setRoot('AdminPage');
}
}
return true;
}
和outputFormat
。例如:
formatForInput
答案 2 :(得分:0)
我最近遇到了同样的错误,问题是这一行:
let thresholdValue = arguments?["thresholdValue"] as? Float
在较新的 Swift 版本中失败,因为 arguments?["thresholdValue"]
包含一个 Double
,此时尝试将其转换为 Float
将失败。将行更改为
let thresholdValue = arguments?["thresholdValue"] as? Double
并在 MPSImageThresholdBinary
的初始值设定项中再次浮动。
thresholdValue: Float(thresholdValue)