Counting stripes

Hello, I am trying to get object count from the image.

image

Here is my stackoverflow question link below:

I checked some article but not found code or reference link on Objective- C or Swift.
I need to do this on either on Objective- C or Swift.

If possible then please suggest me some reference link. Thank You!

if you want help from us, ask a real question here,
just dropping a link to a question on SO is only lame

(i’d seriously like to downvote this, but i can’t)

I agree, the quality of this question is awful. I’ve edited your post so it’s remotely useful.

since you’re a beginner, you ask for approaches but you should not pick your own. template matching is wrong here.

you should post a variety of pictures that represent the problem well. that one picture seems too clean and clear to be the whole truth.

if that picture is the complete truth, you can count the stripes using one of various approaches

  • SimpleBlobDetector (and counting them)
  • findContours (and counting them)
  • finding connected components (and counting them)
  • reducing the problem from 2D to 1D and doing the same as above
  • 1D profile/scanline, calculate derivative, find extrema

SimpleBlobDetector:

#!/usr/bin/env python3
import numpy as np
import cv2 as cv

params = cv.SimpleBlobDetector_Params()
params.filterByArea = False
params.filterByCircularity = False
params.filterByColor = False
params.filterByConvexity = False
params.filterByInertia = False

det = cv.SimpleBlobDetector_create(params)

im = cv.imread("6USx4.png")

blobs = det.detect(im)

for blob in blobs:
    print("center", blob.pt)
center (434.9530029296875, 92.0004653930664)
center (344.7778625488281, 92.0037841796875)
center (254.49986267089844, 91.99874114990234)
center (164.2200164794922, 92.00553894042969)
center (74.04650115966797, 91.99654388427734)

that is python code but I’m sure you can understand what is going on and translate that to your language of choice.

2 Likes