简体   繁体   English

了解如何将边界框坐标与图像匹配

[英]Understanding how to match bounding box coordinates with image

After many attempts I'm able to match the bounding box of Tensorflow tfjs Coco-SSD with the actual image of my phone camera, but I really don't understand how I did it, let me explain:经过多次尝试,我能够将 Tensorflow tfjs Coco-SSD 的边界框与我手机摄像头的实际图像匹配,但我真的不明白我是怎么做到的,让我解释一下:

The output of the model looks like this: bbox: [x, y, width, height] model 的 output 看起来像这样: bbox: [x, y, width, height]

I discovered just by brute force that if I multiply each value for 2.5 everything match perfectly.我只是通过蛮力发现,如果我将每个值乘以 2.5,一切都完美匹配。 But I have no idea where that 2.5 comes from, and I would suspect that may not work in phones with other dimensions, so if anyone could help me to understand this it would be very helpful.但我不知道 2.5 是从哪里来的,我怀疑它可能不适用于其他尺寸的手机,所以如果有人能帮助我理解这一点,那将非常有帮助。

Thanks!谢谢!

My code looks like this:我的代码如下所示:

<TouchableOpacity style={{...styles.box, borderColor: 'red', 
            left: p.bbox[0]*2.5, // p.bbox[0], 
            top: p.bbox[1]*2.5,
            width: p.bbox[2]*2.5, 
            height: p.bbox[3]*2.5}}>              
            </TouchableOpacity>

what you're passing to tfjs is an image data in some resolution (is it video or image or canvas, doesn't matter - it all comes down to image data at the end).您传递给 tfjs 的是某种分辨率的图像数据(是视频还是图像还是 canvas,没关系 - 最后都归结为图像数据)。

then module resizes it to whatever resolution model is trained on.然后模块将其调整为 model 训练的任何分辨率。

and model results are relative to that resolution, not to your input.和 model 结果与该分辨率相关,与您的输入无关。 so you need to take a look at whatever is actual model resolution and rescale results accordingly.因此,您需要查看实际的 model 分辨率并相应地重新调整结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM