@@ -52,6 +52,8 @@ const BiteSelection = (props) => {
52
52
let textFontSize = isPortrait ? '2.5vh' : '2vw'
53
53
// Indicator of how to arrange screen elements based on orientation
54
54
let dimension = isPortrait ? 'column' : 'row'
55
+ // Whether to scale all the masks equally or not
56
+ const scaleMasksEqually = false
55
57
56
58
/**
57
59
* Create a local state variable to store the detected masks, the
@@ -284,17 +286,6 @@ const BiteSelection = (props) => {
284
286
if ( actionStatus . actionStatus === ROS_ACTION_STATUS_SUCCEED ) {
285
287
// If we have a result and there are detected items
286
288
if ( actionResult && actionResult . detected_items && actionResult . detected_items . length > 0 ) {
287
- // Get the size of the largest mask
288
- let [ maxWidth , maxHeight ] = [ 0 , 0 ]
289
- for ( let detected_item of actionResult . detected_items ) {
290
- if ( detected_item . roi . width > maxWidth ) {
291
- maxWidth = detected_item . roi . width
292
- }
293
- if ( detected_item . roi . height > maxHeight ) {
294
- maxHeight = detected_item . roi . height
295
- }
296
- }
297
-
298
289
// Get the allotted space per mask
299
290
let parentWidth , parentHeight
300
291
if ( maskButtonParentRef . current ) {
@@ -320,10 +311,26 @@ const BiteSelection = (props) => {
320
311
* Determine how much to scale the masks so that the largest mask fits
321
312
* into the alloted space.
322
313
*/
323
- let widthScaleFactor = allottedSpaceWidth / maxWidth
324
- let heightScaleFactor = allottedSpaceHeight / maxHeight
325
- let maskScaleFactor = Math . min ( widthScaleFactor , heightScaleFactor )
326
- // maskScaleFactor = Math.min(maskScaleFactor, 1.0)
314
+ // Get the size of the largest mask
315
+ let [ maxWidth , maxHeight ] = [ 0 , 0 ]
316
+ if ( scaleMasksEqually ) {
317
+ for ( let detected_item of actionResult . detected_items ) {
318
+ if ( detected_item . roi . width > maxWidth ) {
319
+ maxWidth = detected_item . roi . width
320
+ }
321
+ if ( detected_item . roi . height > maxHeight ) {
322
+ maxHeight = detected_item . roi . height
323
+ }
324
+ }
325
+ }
326
+ // Create a list to contain the scale factors for each mask
327
+ let maskScaleFactors = [ ]
328
+ for ( let detected_item of actionResult . detected_items ) {
329
+ let widthScaleFactor = allottedSpaceWidth / ( scaleMasksEqually ? maxWidth : detected_item . roi . width )
330
+ let heightScaleFactor = allottedSpaceHeight / ( scaleMasksEqually ? maxHeight : detected_item . roi . height )
331
+ let maskScaleFactor = Math . min ( widthScaleFactor , heightScaleFactor )
332
+ maskScaleFactors . push ( maskScaleFactor )
333
+ }
327
334
328
335
return (
329
336
< View style = { { flexDirection : 'row' , justifyContent : 'center' , alignItems : 'center' , width : '100%' , height : '100%' } } >
@@ -334,7 +341,7 @@ const BiteSelection = (props) => {
334
341
buttonSize = { buttonSize }
335
342
maskSrc = { 'data:image/jpeg;base64,' + detected_item . mask . data }
336
343
invertMask = { true }
337
- maskScaleFactor = { maskScaleFactor }
344
+ maskScaleFactor = { maskScaleFactors [ i ] }
338
345
maskBoundingBox = { detected_item . roi }
339
346
onClick = { foodItemClicked }
340
347
value = { i . toString ( ) }
@@ -345,7 +352,7 @@ const BiteSelection = (props) => {
345
352
)
346
353
}
347
354
}
348
- } , [ actionStatus , actionResult , foodItemClicked , isPortrait , windowSize , margin ] )
355
+ } , [ actionStatus , actionResult , foodItemClicked , isPortrait , windowSize , margin , scaleMasksEqually ] )
349
356
350
357
/** Get the button for continue without acquiring bite
351
358
*
0 commit comments