I implement a component labeling algorithm, as in this article , using python and opencv. This requires checking the input image by pixels and executing the so-called contour trace routine to assign a label to the blocks of the binary image.
I managed to run it, but it seems very slow. Code profiling shows what seems like a bottleneck for a cycle to access pixels. It takes about 200 ms for a 256px * 256px image. Here is roughly what I am doing:
for i in image.height: for j in image.width: p = image[i, j] pa = image[i - 1, j] pb = image[i + 1, j]
where the "image" is the opencv binary image.
I wonder if there is a faster way to do this so that it is useful for video applications. I am aiming for something like a 40-50 ms time for the same problem size to get 20-25 frames per second. 10-15fps is likely to be acceptable (runtime 66-100 ms).
Any tips, ideas that I can do are greatly appreciated.
source share