【问题标题】:How to change CVPixelBuffer data format如何更改 CVPixelBuffer 数据格式
【发布时间】:2019-03-19 13:58:19
【问题描述】:

我将 UIImage 转换为 CoreML 的 CVPixelBuffer,但我想更改 RGB 像素,例如 R/1.5、G/2、B/2.5。

我可以使用assumingMemoryBound(to : UInt8.self)读取像素数据,但是 如何修改CVPixelBuffer中的像素数据?

【问题讨论】:

    标签: swift coreml cvpixelbuffer


    【解决方案1】:

    为什么要在 CVPixelBuffer 中执行此操作?作为模型的一部分,Core ML 可以自动为您执行此操作。

    当您将模型转换为 Core ML 时,您可以指定 image_scale 预处理选项。

    在您的情况下,您似乎希望每个颜色通道都有不同的比例,您可以通过向模型添加缩放层来实现。有关示例,请参见以下 Jupyter 笔记本:https://github.com/apple/coremltools/blob/master/examples/Image_preprocessing_per_channel_scale.ipynb

    【讨论】:

    • 感谢您的回复!这个方法我试过了,但是用spec.neuralNetwork什么都没有,你有什么想法吗?
    • 你用的是什么型号的?
    • 我很抱歉我不知道这种模型是什么意思,我使用以下代码将h5模型转换为mlmodel:coreml_model = coremltools.converters.keras.convert(model, input_names='image', image_input_names='image', red_bias=redbias, green_bias=greenbias, blue_bias=bluebias, output_names='prediction', class_labels=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])有什么问题吗?
    • 非常感谢,你说的问题我已经明白了。我把spec.neuralNetwork改成spec.neuralNetworkClassifier就解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 2013-07-25
    • 2020-11-21
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2018-04-02
    相关资源
    最近更新 更多