Project import generated by Copybara.

GitOrigin-RevId: d8caa66de45839696f5bd0786ad3bfbcb9cff632
This commit is contained in:
MediaPipe Team
2020-12-09 22:43:33 -05:00
committed by chuoling
parent f15da632de
commit 2b58cceec9
750 changed files with 22901 additions and 9478 deletions
+7 -2
View File
@@ -1,3 +1,5 @@
load("//mediapipe/framework/tool:mediapipe_graph.bzl", "mediapipe_binary_graph")
package(default_visibility = ["//visibility:private"])
licenses(["notice"])
@@ -55,6 +57,7 @@ objc_library(
hdrs = MEDIAPIPE_IOS_HDRS,
copts = [
"-Wno-shorten-64-to-32",
"-std=c++17",
],
sdk_frameworks = [
# Needed for OpenCV.
@@ -125,6 +128,7 @@ objc_library(
],
copts = [
"-Wno-shorten-64-to-32",
"-std=c++17",
],
visibility = ["//mediapipe/framework:mediapipe_internal"],
deps = [
@@ -164,6 +168,7 @@ objc_library(
],
copts = [
"-Wno-shorten-64-to-32",
"-std=c++17",
],
sdk_frameworks = [
"CoreVideo",
@@ -186,6 +191,7 @@ objc_library(
],
copts = [
"-Wno-shorten-64-to-32",
"-std=c++17",
],
sdk_frameworks = [
"Accelerate",
@@ -216,6 +222,7 @@ objc_library(
],
copts = [
"-Wno-shorten-64-to-32",
"-std=c++17",
],
data = [
"testdata/googlelogo_color_272x92dp.png",
@@ -240,8 +247,6 @@ objc_library(
],
)
load("//mediapipe/framework/tool:mediapipe_graph.bzl", "mediapipe_binary_graph")
[
mediapipe_binary_graph(
name = graph.split("/")[-1].rsplit(".", 1)[0] + "_graph",
+2 -2
View File
@@ -111,6 +111,7 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName,
didOutputPacket:packet
fromStream:streamName];
} else if (packetType == MPPPacketTypeImageFrame) {
wrapper->_framesInFlight--;
const auto& frame = packet.Get<mediapipe::ImageFrame>();
mediapipe::ImageFormat::Format format = frame.Format();
@@ -163,6 +164,7 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName,
}
#if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
} else if (packetType == MPPPacketTypePixelBuffer) {
wrapper->_framesInFlight--;
CVPixelBufferRef pixelBuffer = packet.Get<mediapipe::GpuBuffer>().GetCVPixelBufferRef();
if ([wrapper.delegate
respondsToSelector:@selector
@@ -182,8 +184,6 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName,
} else {
_GTMDevLog(@"unsupported packet type");
}
wrapper->_framesInFlight--;
}
}
+15
View File
@@ -84,6 +84,21 @@
maxLocalDifference:(int)maxLocalDiff
maxAverageDifference:(float)maxAvgDiff;
/// Compares two pixel buffers with some leniency.
/// Returns true iff the two buffers have the same size and format, and:
/// - the difference between each pixel of A and the corresponding pixel of B does
/// not exceed maxLocalDiff, and
/// - the average difference between corresponding pixels of A and B does not
/// exceed maxAvgDiff.
/// The maximum local difference and average difference will be written
/// to @c maxLocalDiffOut and @c maxAvgDiffOut respectively.
- (BOOL)pixelBuffer:(CVPixelBufferRef)a
isCloseTo:(CVPixelBufferRef)b
maxLocalDifference:(int)maxLocalDiff
maxAverageDifference:(float)maxAvgDiff
maxLocalDifferenceOut:(int*)maxLocalDiffOut
maxAverageDifferenceOut:(float*)maxAvgDiffOut;
/// Utility function for making a copy of a pixel buffer with a different pixel
/// format.
- (CVPixelBufferRef)convertPixelBuffer:(CVPixelBufferRef)input toPixelFormat:(OSType)pixelFormat;
+34 -8
View File
@@ -187,8 +187,24 @@ static void EnsureOutputDirFor(NSString *outputFile) {
return [self pixelBuffer:a isCloseTo:b maxLocalDifference:0 maxAverageDifference:0];
}
- (BOOL)pixelBuffer:(CVPixelBufferRef)a isCloseTo:(CVPixelBufferRef)b
maxLocalDifference:(int)maxLocalDiff maxAverageDifference:(float)maxAvgDiff {
- (BOOL)pixelBuffer:(CVPixelBufferRef)a
isCloseTo:(CVPixelBufferRef)b
maxLocalDifference:(int)maxLocalDiff
maxAverageDifference:(float)maxAvgDiff {
return [self pixelBuffer:a
isCloseTo:b
maxLocalDifference:maxLocalDiff
maxAverageDifference:maxAvgDiff
maxLocalDifferenceOut:nil
maxAverageDifferenceOut:nil];
}
- (BOOL)pixelBuffer:(CVPixelBufferRef)a
isCloseTo:(CVPixelBufferRef)b
maxLocalDifference:(int)maxLocalDiff
maxAverageDifference:(float)maxAvgDiff
maxLocalDifferenceOut:(int*)maxLocalDiffOut
maxAverageDifferenceOut:(float*)maxAvgDiffOut {
size_t aBytesPerRow = CVPixelBufferGetBytesPerRow(a);
size_t aWidth = CVPixelBufferGetWidth(a);
size_t aHeight = CVPixelBufferGetHeight(a);
@@ -229,17 +245,19 @@ static void EnsureOutputDirFor(NSString *outputFile) {
// even if bytesPerRow match.
size_t usedRowWidth = aWidth * bytesPerPixel;
BOOL equal = YES;
float averageDiff = 0;
float count = 0;
BOOL canSkipSomeDiffs = !maxLocalDiffOut && !maxAvgDiffOut;
int computedMaxLocalDiff = 0;
float computedAvgDiff = 0;
for (int i = aHeight; i > 0 && equal; --i) {
if (maxLocalDiff == 0) {
if (maxLocalDiff == 0 && canSkipSomeDiffs) {
// If we can, use memcmp for speed.
equal = memcmp(aData, bData, usedRowWidth) == 0;
} else {
for (int j = 0; j < usedRowWidth; j++) {
int diff = abs(aData[j] - bData[j]);
if (diff > maxLocalDiff) {
equal = NO;
computedMaxLocalDiff = MAX(computedMaxLocalDiff, diff);
if (diff > maxLocalDiff && canSkipSomeDiffs) {
break;
}
// We use Welford's algorithm for computing a sample mean. This has better
@@ -247,13 +265,21 @@ static void EnsureOutputDirFor(NSString *outputFile) {
// particularly matters here.
// Welford: http://www.jstor.org/stable/1266577
// Knuth: The Art of Computer Programming Vol 2, section 4.2.2
averageDiff += (diff - averageDiff) / ++count;
computedAvgDiff += (diff - computedAvgDiff) / ++count;
}
}
aData += aBytesPerRow;
bData += bBytesPerRow;
}
if (averageDiff > maxAvgDiff) equal = NO;
if (computedMaxLocalDiff > maxLocalDiff || computedAvgDiff > maxAvgDiff) {
equal = NO;
}
if (maxLocalDiffOut) {
*maxLocalDiffOut = computedMaxLocalDiff;
}
if (maxAvgDiffOut) {
*maxAvgDiffOut = computedAvgDiff;
}
err = CVPixelBufferUnlockBaseAddress(b, kCVPixelBufferLock_ReadOnly);
XCTAssertEqual(err, kCVReturnSuccess);