opencv/javacv: How to iterate over contours for shape identification?

前端 未结 3 781

I\'m developing a shape identification project using JavaCV and I have found some OpenCV code to identify U shapes in a particular image. I have tried to convert it into JavaCV

3条回答
  •  太阳男子
    2021-02-08 17:41

    Check your type promotions, e.g.:

    if (10 < (w/h) || (w/h) < 0.1){
    

    .. is highly suspect. To get a floating point division, one (or both) of the operands must at least be a float (and likewise a double for double division). Otherwise, as in this case, it is an integer division. (Note that the original code has promotion to float as well.)

    For instance:

     float ratio = (float)w/h; // (float / int) => (float / float) -> float
     if (10 < ratio || ratio < 0.1 ) { 
    

    (Although I am unsure if this is the issue here.)

    Happy coding!

提交回复
热议问题