Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegFault in connectedComponents with connectivity = 4 #706

Closed
raphaelreme opened this issue Aug 8, 2022 · 3 comments
Closed

SegFault in connectedComponents with connectivity = 4 #706

raphaelreme opened this issue Aug 8, 2022 · 3 comments
Assignees

Comments

@raphaelreme
Copy link

Hello !

I was experiencing with cv2.connectedComponents in python and with the connectivity argument (Wanted to use 4 instead of 8), and I faced a SegFault error when using this function without giving the output labels array as parameter (and letting opencv allocating it for me)

I'm not sure whether it is a bug of opencv or opencv python. So I just opened the issue here.

Steps to reproduce

Example that yields a SegFault

import cv2
import numpy as np

mask = np.array([[0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 1]], dtype=np.uint8)

n, labels = cv2.connectedComponents(mask, connectivity=4)

# SegFault

A solution without SegFault and the good result

import cv2
import numpy as np

mask = np.array([[0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 1]], dtype=np.uint8)
labels = np.zeros(mask.shape, dtype=np.int32)

n, labels = cv2.connectedComponents(mask, labels, connectivity=4)

# No SegFault
# labels is
# 0 1 1 0
# 0 1 1 0
# 0 0 0 2
# 0 0 2 2

This behavior does not seem to happen with connectivity=8

I'm on Ubuntu 20.4 64bits (x86_64)
Using Python 3.8.13
and OpenCv-python 4.5.5.64

@raphaelreme raphaelreme changed the title SegFault in connectedComponents with connectitivy = 4 SegFault in connectedComponents with connectivity = 4 Aug 8, 2022
@asmorkalov asmorkalov self-assigned this Aug 10, 2022
@asmorkalov
Copy link
Collaborator

The issue is reproducible with 4.5.5, but not for 4.6.0 and current 4.x branch. Please update your OpenCV installation.

@asmorkalov
Copy link
Collaborator

Most probably duplicate of opencv/opencv#21783

@raphaelreme
Copy link
Author

Oh yes indeed, the new version has fixed the issue! Thanks for your answer!

LinasKo added a commit to emSko/supervision that referenced this issue May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants