File size: 1,437 Bytes
2a4cd0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
async function cropImage(imageUri, topLeftCoords, bottomRightCoords) {
const { uri } = await ImageManipulator.manipulateAsync(
imageUri,
[
{
crop: {
originX: topLeftCoords.x,
originY: topLeftCoords.y,
width: bottomRightCoords.x - topLeftCoords.x,
height: bottomRightCoords.y - topLeftCoords.y,
},
},
],
{ compress: 1, format: ImageManipulator.SaveFormat.JPEG }
);
return uri;
}
export class ModelService {
// ... (existing code)
async classifyCroppedImages(image: ImageManipulator.ImageResult, topLeftCoords1, bottomRightCoords1, topLeftCoords2, bottomRightCoords2): Promise<IModelPredictionResponse[]> {
const croppedImageUri1 = await cropImage(image.uri, topLeftCoords1, bottomRightCoords1);
const croppedImageUri2 = await cropImage(image.uri, topLeftCoords2, bottomRightCoords2);
const croppedImage1: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
croppedImageUri1,
[],
{ base64: true }
);
const croppedImage2: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
croppedImageUri2,
[],
{ base64: true }
);
const [predictionResponse1, predictionResponse2] = await Promise.all([
this.classifyImage(croppedImage1),
this.classifyImage(croppedImage2),
]);
return [predictionResponse1, predictionResponse2];
}
}
|