Object segmentation not working for black object
up vote
1
down vote
favorite
I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.
However, my script seems to fail on dark coloured objects:
I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:
import cv2
import imutils
image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
Any suggestions on how I can improve this?
opencv image-segmentation
add a comment |
up vote
1
down vote
favorite
I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.
However, my script seems to fail on dark coloured objects:
I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:
import cv2
import imutils
image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
Any suggestions on how I can improve this?
opencv image-segmentation
2
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.
However, my script seems to fail on dark coloured objects:
I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:
import cv2
import imutils
image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
Any suggestions on how I can improve this?
opencv image-segmentation
I am working on a Python script for object segmentation, using opencv. On some objects, this script already works fine. See for example the image below.
However, my script seems to fail on dark coloured objects:
I don't know why this is since I am pretty new to computer vision. My script for object segmentation looks like this:
import cv2
import imutils
image = cv2.imread(input)
dst = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
hsv = cv2.cvtColor(dst, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
retval, thresholded = cv2.threshold(s, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
medianFiltered = cv2.medianBlur(thresholded, 5)
cnts = cv2.findContours(medianFiltered,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
Any suggestions on how I can improve this?
opencv image-segmentation
opencv image-segmentation
asked Nov 19 at 14:03
JNevens
2,05962451
2,05962451
2
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45
add a comment |
2
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45
2
2
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376329%2fobject-segmentation-not-working-for-black-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
well, if you think about it... in HSV colorspace the color black is basically when the V channel is close to 0 (doesn't matter the other two channels much)... and you threshold and use the saturation channel which in this case may be quite low. For filtering black over very light backgrounds, maybe it is easier to threshold a greyscale image? however in that case, maybe the line under the door may be an issue
– api55
Nov 19 at 16:34
Thank you for your suggestion. I have experimented with filtering a grayscale version of the image a bit. However, the difficulty here was finding a good threshold such that the yellow object would be detected.
– JNevens
Nov 19 at 16:45