Updated formatting
This commit is contained in:
parent
42e35503d9
commit
ae05c78443
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2019 The MediaPipe Authors.
|
// Copyright 2023 The MediaPipe Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -19,9 +19,9 @@
|
||||||
#include "mediapipe/framework/formats/image.h"
|
#include "mediapipe/framework/formats/image.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
using ::mediapipe::Image;
|
||||||
using ::mediapipe::MakePacket;
|
using ::mediapipe::MakePacket;
|
||||||
using ::mediapipe::Packet;
|
using ::mediapipe::Packet;
|
||||||
using ::mediapipe::Image;
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct freeDeleter {
|
struct freeDeleter {
|
||||||
|
@ -31,7 +31,6 @@ struct freeDeleter {
|
||||||
@implementation MPPVisionPacketCreator
|
@implementation MPPVisionPacketCreator
|
||||||
|
|
||||||
+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error {
|
+ (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error {
|
||||||
|
|
||||||
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
|
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
|
||||||
|
|
||||||
if (!imageFrame) {
|
if (!imageFrame) {
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
|
|
||||||
#include "mediapipe/framework/formats/image_frame.h"
|
#include "mediapipe/framework/formats/image_frame.h"
|
||||||
|
#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@interface MPPImage (Utils)
|
@interface MPPImage (Utils)
|
||||||
/**
|
/**
|
||||||
* Converts the `MPPImage` into a `mediapipe::ImageFrame`.
|
* Converts the `MPPImage` into a `mediapipe::ImageFrame`.
|
||||||
* Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is converted to an RGB format. In case of grayscale images, the mono channel is duplicated
|
* Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is
|
||||||
* in the R, G, B channels.
|
* converted to an RGB format. In case of grayscale images, the mono channel is duplicated in the R,
|
||||||
|
* G, B channels.
|
||||||
*
|
*
|
||||||
* @param error Pointer to the memory location where errors if any should be
|
* @param error Pointer to the memory location where errors if any should be
|
||||||
* saved. If @c NULL, no error will be saved.
|
* saved. If @c NULL, no error will be saved.
|
||||||
|
|
|
@ -41,7 +41,8 @@ namespace {
|
||||||
|
|
||||||
@interface MPPCVPixelBufferUtils : NSObject
|
@interface MPPCVPixelBufferUtils : NSObject
|
||||||
|
|
||||||
+ (std::unique_ptr<ImageFrame>)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error;
|
+ (std::unique_ptr<ImageFrame>)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer
|
||||||
|
error:(NSError **)error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -124,15 +125,14 @@ namespace {
|
||||||
|
|
||||||
@implementation MPPCVPixelBufferUtils
|
@implementation MPPCVPixelBufferUtils
|
||||||
|
|
||||||
+ (std::unique_ptr<ImageFrame>)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error {
|
+ (std::unique_ptr<ImageFrame>)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer
|
||||||
|
error:(NSError **)error {
|
||||||
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
|
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
|
||||||
|
|
||||||
size_t width = CVPixelBufferGetWidth(pixelBuffer);
|
size_t width = CVPixelBufferGetWidth(pixelBuffer);
|
||||||
size_t height = CVPixelBufferGetHeight(pixelBuffer);
|
size_t height = CVPixelBufferGetHeight(pixelBuffer);
|
||||||
size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer);
|
size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t *rgbPixelData = [MPPPixelDataUtils
|
uint8_t *rgbPixelData = [MPPPixelDataUtils
|
||||||
rgbPixelDataFromPixelData:(uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer)
|
rgbPixelDataFromPixelData:(uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer)
|
||||||
withWidth:CVPixelBufferGetWidth(pixelBuffer)
|
withWidth:CVPixelBufferGetWidth(pixelBuffer)
|
||||||
|
@ -147,9 +147,9 @@ namespace {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ImageFrame> imageFrame = absl::make_unique<ImageFrame>(
|
std::unique_ptr<ImageFrame> imageFrame =
|
||||||
::mediapipe::ImageFormat::SRGB, /*width=*/width, /*height=*/height, stride,
|
absl::make_unique<ImageFrame>(::mediapipe::ImageFormat::SRGB, /*width=*/width,
|
||||||
static_cast<uint8*>(rgbPixelData),
|
/*height=*/height, stride, static_cast<uint8 *>(rgbPixelData),
|
||||||
/*deleter=*/free);
|
/*deleter=*/free);
|
||||||
|
|
||||||
return imageFrame;
|
return imageFrame;
|
||||||
|
@ -235,10 +235,8 @@ namespace {
|
||||||
@implementation UIImage (ImageFrameUtils)
|
@implementation UIImage (ImageFrameUtils)
|
||||||
|
|
||||||
- (std::unique_ptr<ImageFrame>)imageFrameFromCIImageWithError:(NSError **)error {
|
- (std::unique_ptr<ImageFrame>)imageFrameFromCIImageWithError:(NSError **)error {
|
||||||
|
|
||||||
if (self.CIImage.pixelBuffer) {
|
if (self.CIImage.pixelBuffer) {
|
||||||
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer
|
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer error:error];
|
||||||
error:error];
|
|
||||||
|
|
||||||
} else if (self.CIImage.CGImage) {
|
} else if (self.CIImage.CGImage) {
|
||||||
return [MPPCGImageUtils imageFrameFromCGImage:self.CIImage.CGImage error:error];
|
return [MPPCGImageUtils imageFrameFromCGImage:self.CIImage.CGImage error:error];
|
||||||
|
@ -278,8 +276,7 @@ namespace {
|
||||||
switch (self.imageSourceType) {
|
switch (self.imageSourceType) {
|
||||||
case MPPImageSourceTypeSampleBuffer: {
|
case MPPImageSourceTypeSampleBuffer: {
|
||||||
CVPixelBufferRef sampleImagePixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer);
|
CVPixelBufferRef sampleImagePixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer);
|
||||||
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer
|
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer error:error];
|
||||||
error:error];
|
|
||||||
}
|
}
|
||||||
case MPPImageSourceTypePixelBuffer: {
|
case MPPImageSourceTypePixelBuffer: {
|
||||||
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.pixelBuffer error:error];
|
return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.pixelBuffer error:error];
|
||||||
|
|
|
@ -29,7 +29,8 @@ NS_SWIFT_NAME(ImageClassifierOptions)
|
||||||
@property(nonatomic) MPPRunningMode runningMode;
|
@property(nonatomic) MPPRunningMode runningMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user-defined result callback for processing live stream data. The result callback should only be specified when the running mode is set to the live stream mode.
|
* The user-defined result callback for processing live stream data. The result callback should only
|
||||||
|
* be specified when the running mode is set to the live stream mode.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, copy) void (^completion)(MPPImageClassifierResult *result, NSError *error);
|
@property(nonatomic, copy) void (^completion)(MPPImageClassifierResult *result, NSError *error);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user