0

I am trying to detect a mark on a object and determine if it is left from the centre or the right. Following marked with green arrow is what i am trying to detect :

Image:

enter image description here

I have read the opencv documentation but cant find a way to do something similar. The basic step for now is to just detect the specific detail of the image and has to work every single time then i am looking forward to determining if it is on right or left.

How can i do this

Edit : I have tried shawn's method to see if it work and has the answer the only problem is that with my experimenting i cant seem to get a perfect a value as shown in the shawn's answer.

9
  • Do I understand correctly that you already have an instance running, that finds the mark? What is the output type? Are there any meta information? Commented May 6, 2021 at 12:08
  • No i do not have any instances running i was just trying to find a way to find the mark. Commented May 6, 2021 at 12:11
  • 1
    Please Provide Some More Code Commented May 6, 2021 at 13:10
  • You could try thresholding and then getting the contours. From that, get the contour of the right size. Or if that region is always that size and shape, you could do template matching. What have yo tried? Commented May 6, 2021 at 17:55
  • @fmw42 I have tried that but i often don get the mark but i get the semi circle only Commented May 7, 2021 at 6:41

3 Answers 3

1

I guess it is a microscope output.

First you have to detect (locate) objects in the image :

  1. My default solution would be object detection with machine learning models. This is the way if you have lots of labeled data (e.g annotated image). For example, you can train a YOLOv3 tiny model for this problem. Without diving into too much code, you can find the tutorial for detecting something different, and apply it to your problem. For example, you can follow this tutorial, then you will ask more specific questions.

  2. If you are familiar with object detection with machine learning and frameworks like PyTorch and TensorFlow, you can find lighter models than YOLOv3 tiny from the GitHub, and you can re-train them.

You can achieve insane accuracies using machine learning, however, there are other methods :

  1. Other solutions rather than machine learning may be object detection using contour plots or object detection using HSV color space. You can find other Image Processing methods without machine learning on YouTube or other tutorial platforms.

Maybe you can follow these tutorials and then ask more specific code-related questions like "Why is the blurring is not working on my contour plot code?".

Second, after you are able to detect objects, you should extract the bounding box coordinates center, and compare it with the image center coordinates.

If the X coordinate of the detected object bounding box center is greater than the (width of the image)/2, then the object is on the right of the image. If it is smaller, then the detected object is on the left side of the image.

Hope this answers your question.

Sign up to request clarification or add additional context in comments.

Comments

0

If your images are all relatively similar, you should be able to apply some filters (Blur & thresholding) to accentuate the area of interest.

After that; do some blob detection:

in fact; I was able to accomplish just that using the answer in the link below; with some minor tweaking.

OpenCVs BlobDetector crashes

enter image description here

3 Comments

What were you values from this and can i make bounding box around it
it would be appreaciated if you could show some code
can you draw a bounding box? I don't see why not...I'd highly encourage some due diligence and take a look at the post I referenced. Here are the filters I used with no concrete logic behind why I modified those values other than observing the output for best results :-) smoothed = cv2.GaussianBlur(gray, (1,1), sigmaX=3, sigmaY=3, borderType = cv2.BORDER_DEFAULT) thresh = cv2.adaptiveThreshold(smoothed, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 65, 55) params.minArea = 500 params.filterByCircularity = False params.filterByConvexity = False params.filterByInertia = False
0

I have tried using HSV Object Detection and Have Got Some Pretty Good Results but now the only problem is that i have only masked version of image from which i want to detect the mark which is a pretty medium sized contour

This image will clarify it : (What I Have Achieved )

1 Comment

I think that you may want to investigate some filters that are interested in "change" in the grayscale because the top half of your image is relatively light in color, the bottom half dark (neither of which are of interest to you?) what IS interesting is the small speck in that travels from light to dark and back to light again. Those changes are easy to filter in opencv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.