0

Hope you guys are doing well.

I have a question about opencv and extracting the same point from number of images.

Say, we have a dataset of around 100 images. (maybe more but for this purpose it will suffice).

Image will look something like:

enter image description here

As you can see in the image, there is an area marked in RED. I have marked that using Paint for this purpose. It indicates the highest point of the heap of soil. All the 100 images we have look more or less the same (without that crane in the background. But it can be removed using some opencv techniques, so that is not an issue). But this heap of soil can be either on the left hand side or the right hand side. According to its position, the coordinate of the highest point in the heap will change.

So, my question is, how to find this position given that the heap can be either on left or right side? Note that this position can be relative to some object (for example in this image, midpoint of the crane) or if the images are of different size than we can resize the images to have same dimensions and take the coordinates of the point w.r.t the image itself.

How do we find out the highest point of the heap though? Should we manually go through each image, label that point and make a dataset with the images and bounding boxes? Or is there another decent soulution to this?

Also, if the soil heap is labelled manually (Like shading the required area i.e. heap of an image) using Paint or some other software, would that help too? But I cannot think of anything to do after this.

Thank You.

y_1234
  • 61
  • 1
  • 7
  • I think in real world you'll need deep learning for this, and a lot of training data – Micka May 24 '20 at 08:30
  • I have this in my mind. I was thinking of building a classification model. But I won't have more than 200 images. Do you think that will suffice? Also, manually labelling them, drawing bounding boxes on all training images is tedious, I think. What do you think? – y_1234 May 24 '20 at 08:33
  • 1. You can detect edges in image (Canny). 2. Hought transformation and detect lines. 3. Select lines by angle of respose. See https://en.wikipedia.org/wiki/Angle_of_repose – Alex Alex May 24 '20 at 15:58
  • if you know that there is a pile in the image and coarsely where it is, edges/lines and angle of repose might work ok – Micka May 24 '20 at 17:00

3 Answers3

0

So I am sure this can be done in a better way than my answer, but here goes: "Also, if the soil heap is labelled manually (Like shading the required area i.e. heap of an image) using Paint or some other software, would that help too? But I cannot think of anything to do after this."

In regards to that particular statement if you mark out the region of interest in a distinctive color and shape, like you have done in the above example. You can use opencv to detect that particular region of interest and its coordinates within the image.

Akib Rhast
  • 651
  • 4
  • 15
  • So that means, labelling the portion manually is a must? Also, I have mentioned in the question, what if the heap is on left hand side? How do I get the coordinates? – y_1234 May 24 '20 at 07:18
  • So, like I mentioned in my post, I am sure there is a better way which is beyond me. But if you were to mark out the area. This post gives you how to detect a colored circle:https://stackoverflow.com/questions/38827505/detecting-colored-circle-and-its-center-using-opencv Using that as an example opencv has a built in method that returns coordinate of a given roi – Akib Rhast May 24 '20 at 07:29
0

I think the best solution is deep learning because detective always has different backgrounds. You can use Faster rcnn, or if you want speed, you can make nice detectives with a good training using Yolo algorithm. You can find Github repo easily. The mathematics of work is described in these links.

kaankucuk
  • 19
  • 6
  • Okay Okay. So what I understand is, I have to manually create boxes for each image in the dataset and then use one of the aforementioned methods to train my model. Is that correct? – y_1234 May 24 '20 at 13:23
  • You should do as you say, yes – kaankucuk May 24 '20 at 13:36
  • Oksy, but say for example, the height of the heap changes from one image to another in the dataset (which it will). And, when I will test an image in which heap has a different height than any of the images in the dataset, then what can be done? – y_1234 May 24 '20 at 13:46
0

basically you can resize image. Keep aspect ratio!

def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
    dim = None
    (h, w) = image.shape[:2]

    if width is None and height is None:
        return image

    if width is None:
        # calculate the ratio of the height and construct the
        # dimensions
        r = height / float(h)
        dim = (int(w * r), height)

    else:
        # calculate the ratio of the width and construct the
        # dimensions
        r = width / float(w)
        dim = (width, int(h * r))

    # resize the image
    resized = cv2.resize(image, dim, interpolation = inter)

    # return the resized image
    return resized

image = image_resize(image, height = ..What you want..)
kaankucuk
  • 19
  • 6