Skip to content

Race condition in Canny(), opencv 3 #8149

@schwittmann

Description

@schwittmann
System information (version)
  • OpenCV => 3.1.0-7
  • Operating System / Platform => 4.9.2-1-MANJARO x86-64
  • Compiler => 6.3.1 20170109 (GCC)
  • No OpenCl, Tegra or IPP
Detailed description

We wanted our opencv based source code to be compatible with both opencv 2.4 and 3.x. However, our program yielded unexpected results with 3.x. After some rigorous debugging we discovered the bug in Canny(). While the documentation states that the output matrix "can be the same as the input" this causes the problem. If we use a dedicated output matrix the results are as expected.

We assume that parallelization optimizations in 3.x causes this problem. Multiple threads operate read and write on the same matrix causing race conditions.

Steps to reproduce
```.cpp
Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
```

On a machine with multiple cpu cores

Workaround
```.cpp
Canny( detected_edges, tmp, lowThreshold, lowThreshold*ratio, kernel_size );
```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions