1 | initial version |
Try simpler methods than classifiers.
As long as you need only to detect the positions of the objects (not to recognize them), the objects don't touch, and the background is uniform, this is a very simple problem.
Do a thresholding* and a connected component analysis with stats. It will give also the centers of the objects.
If the objects can touch each other (but without having a big overlap), you can do a distance transform on the thresholded image and get the maxima.
[] *For thresholding, either convert the image to grayscale and use the threshold
function, or the inRange
on BGR or HSV image (check cvtColor
); the best method depends on the application.
2 | No.2 Revision |
Try simpler methods than classifiers.
As long as you need only to detect the positions of the objects (not to recognize them), the objects don't touch, and the background is uniform, this is a very simple problem.
Do a thresholding* and a connected component analysis with stats. It will give also the centers of the objects.
If the objects can touch each other (but without having a big overlap), you can do a distance transform on the thresholded image and get the maxima.
[[ANSWER UPDATE] For the new video, you can still use a color segmentation (on the H channel of a HSV image). Having two ranges can separate the image into 2 binary images, each containing one type of objects. Then continue with the connected components.
If the objects can have similar colors but different shapes or sizes, you can identify the object type using the Hu moments (after the connected component analysis).
[ * ] *For For thresholding, either convert the image to grayscale and use the threshold
function, or the inRange
on BGR or HSV image (check cvtColor
); the best method depends on the application.
3 | No.3 Revision |
Try simpler methods than classifiers.
As long as you need only to detect the positions of the objects (not to recognize them), the objects don't touch, and the background is uniform, this is a very simple problem.
Do a thresholding* and a connected component analysis with stats. It will give also the centers of the objects.
If the objects can touch each other (but without having a big overlap), you can do a distance transform on the thresholded image and get the maxima.
[ANSWER UPDATE] For the new video, you can still use a color segmentation (on the H channel of a HSV image). Having two (or more) ranges can separate the image into 2 several binary images, each containing one type of objects. Then continue with the connected components.
If the objects can have similar colors but different shapes or sizes, you can identify the object type using the Hu moments (after the connected component analysis).
[ * ] For thresholding, either convert the image to grayscale and use the threshold
function, or the inRange
on BGR or HSV image (check cvtColor
); the best method depends on the application.
4 | No.4 Revision |
Try simpler methods than classifiers.
As long as you need only to detect the positions of the objects (not to recognize them), the objects don't touch, and the background is uniform, this is a very simple problem.
Do a thresholding* and a connected component analysis with stats. It will give also the centers of the objects.
If the objects can touch each other (but without having a big overlap), you can do a distance transform on the thresholded image and get the maxima.
[ANSWER UPDATE] For the new video, you can still use a color segmentation (on the H channel of a HSV image). Having two (or more) ranges can separate the image into several binary images, each containing one type of objects. Then continue with the connected components.
If the objects can have similar colors but different shapes or sizes, you can identify the object type using the Hu moments (after the connected component analysis).
[ * ] For thresholding, either convert the image to grayscale and use the threshold
function, or the inRange
on BGR or HSV image (check cvtColor
); the best method depends on the application.
*[EDIT 2] Here is a quick result of separating the image into 2 classes, each containing one type of objects (one color). I used the InRange function on the HSV image and the Hue channel. Note that you might need a threshold on the V channel too, to eliminate the compression artifacts.