Skip to content

Commit

Permalink
refactor: apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
chmjkb committed Dec 16, 2024
1 parent edf1f9d commit f9d4a01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
18 changes: 9 additions & 9 deletions ios/RnExecutorch/ObjectDetection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ - (void)forward:(NSString *)input
nil);
return;
}
cv::Mat decodedImage = cv::imdecode(
cv::Mat(1, [data length], CV_8UC1, (void *)data.bytes), cv::IMREAD_COLOR);
NSArray *result = [model runModel:decodedImage];
resolve(result);
}
@catch (NSException *exception) {
reject(@"result_error", [NSString stringWithFormat:@"%@", exception.reason],
nil);
}
cv::Mat decodedImage =
cv::imdecode(cv::Mat(1, [data length], CV_8UC1, (void *)data.bytes),
cv::IMREAD_COLOR);
NSArray *result = [model runModel:decodedImage];
resolve(result);
} @catch (NSException *exception) {
reject(@"result_error", [NSString stringWithFormat:@"%@", exception.reason],
nil);
}
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
Expand Down
8 changes: 4 additions & 4 deletions ios/RnExecutorch/utils/ImageProcessor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ + (NSArray *)matToNSArray:(const cv::Mat &)mat {
int row = i / mat.cols;
int col = i % mat.cols;
cv::Vec3b pixel = mat.at<cv::Vec3b>(row, col);
floatArray[i] = @(pixel[2] / 255.0f);
floatArray[pixelCount + i] = @(pixel[1] / 255.0f);
floatArray[0 * pixelCount + i] = @(pixel[2] / 255.0f);
floatArray[1 * pixelCount + i] = @(pixel[1] / 255.0f);
floatArray[2 * pixelCount + i] = @(pixel[0] / 255.0f);
}

Expand All @@ -31,8 +31,8 @@ + (NSArray *)matToNSArray:(const cv::Mat &)mat {
int col = i % width;
float r = 0, g = 0, b = 0;

r = [[array objectAtIndex: i] floatValue];
g = [[array objectAtIndex: pixelCount + i] floatValue];
r = [[array objectAtIndex: 0 * pixelCount + i] floatValue];
g = [[array objectAtIndex: 1 * pixelCount + i] floatValue];
b = [[array objectAtIndex: 2 * pixelCount + i] floatValue];

cv::Vec3b color((uchar)(b * 255), (uchar)(g * 255), (uchar)(r * 255));
Expand Down
3 changes: 2 additions & 1 deletion src/models/object_detection/ObjectDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export const useObjectDetection = ({
setIsModelGenerating(false);
return output;
} catch (e) {
setIsModelGenerating(false);
throw new Error(getError(e));
} finally {
setIsModelGenerating(false);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/models/object_detection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Bbox {
}

export interface Detection {
bbox: Bbox,
bbox: Bbox;
label: keyof typeof CocoLabel;
score: number;
}
Expand Down Expand Up @@ -101,5 +101,5 @@ enum CocoLabel {
TEDDY_BEAR = 88,
HAIR_DRIER = 89,
TOOTHBRUSH = 90,
HAIR_BRUSH = 91
};
HAIR_BRUSH = 91,
}

0 comments on commit f9d4a01

Please sign in to comment.