Ask Your Question

Which is the best method to detect this object?

asked 2018-07-03 18:07:09 -0500

Jhonas Boeno gravatar image

updated 2018-07-16 18:00:56 -0500

Hi, I'm new to OpenCV and I'm trying to detect an object in a video. In the future, the video will be removed and the source will be screenshots taken from screen.

Check the example here:

This is not a real world, it is a 3D environment. The background is always pure black and I have all the angles of the objects. In the example above I have just two objects but in the future I will have different objects with different shape and color.

Objects will appear in the scene moving through the image and also rotating.

I need some way to get the x and y position of the center of the objects in the image and also get the type of the object.

I tried cascade classifier but it only generates stage0 and files are only 2 kb. I think this is not working because 2 kb is too small for a working classifier.

I would to know which is the best way to do what I need.

edit retag flag offensive close merge delete


please add an image here. a video on an external site is useless.

berak gravatar imageberak ( 2018-07-04 00:39:20 -0500 )edit

Sorry for posting the video, but I did not know how to describe the problem using images since I need to detect objects that move.

Jhonas Boeno gravatar imageJhonas Boeno ( 2018-07-16 18:04:43 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-07-04 04:28:03 -0500

kbarni gravatar image

updated 2018-07-18 07:13:43 -0500

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. image description

edit flag offensive delete link more


Hi. Thanks for answering my question. I think I did not explain my problem correctly, objects need to be recognized since other objects will be in the scene. In this case, what would be the solution?

Jhonas Boeno gravatar imageJhonas Boeno ( 2018-07-13 19:20:50 -0500 )edit

Then please post an image/video with your real problem. The solution will depend on the problem you try to solve and the images you have; not on other things.

For example, differentiating a blue square and a red circle isn't the same as recognizing traffic signs in real world images. Even if the problem might seem similar at first glance.

kbarni gravatar imagekbarni ( 2018-07-15 06:35:26 -0500 )edit

Thank you for insisting on helping me. I have updated my question.

Jhonas Boeno gravatar imageJhonas Boeno ( 2018-07-16 18:02:24 -0500 )edit

@jhonas-boeno Answer updated...

kbarni gravatar imagekbarni ( 2018-07-17 04:29:00 -0500 )edit

I really appreciate your help. I think this may be enough to meet my needs, I will study these methods. Thank you very much.

Jhonas Boeno gravatar imageJhonas Boeno ( 2018-07-17 20:03:35 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-07-03 18:07:09 -0500

Seen: 125 times

Last updated: 2 days ago