linghu8812 / tensorrt_inference

703 stars 206 forks source link

Fix segmentation fault when accessing raw pointer and use round for better accuracy #151

Closed awarebayes closed 2 years ago

awarebayes commented 2 years ago

Simple fix for #147, just check array boundaries

awarebayes commented 2 years ago

Also it makes sense to use std::round instead of cast to int, because int discards obviously bigger 0.75 casting it to zero instead of one. When you analyze videos, (int) results in less temporal coherence and more 'flickering' of keypoints

#include <iostream>
#include <cmath>

int main() {
    float x = 0.75;
    std::cout << (int)x << " vs " << std::round(x) << std::endl;
    return 0;
}
./main
0 vs 1