To measure the number of "C" shapes shown in the ‘picture’ per column [opencv]

  opencv, python

this is full-1.jpg

`import numpy as np`
`import cv2`

`width = 1000`  
`height = 750` 
`area = width*height`

`frame0 = cv2.imread('full-1.jpg')`

`# gray frame`
`frame1 = cv2.cvtColor(frame0,cv2.COLOR_BGR2GRAY)`

`# blur frame`
`frame1 = cv2.GaussianBlur(frame1,(5,5),0)`

`# threshold frame n out of 255 (85 = 33%)`
`frame1 = cv2.threshold(frame1,67,255,cv2.THRESH_BINARY)[1]`

`# invert`
`frame1 = ~frame1`

`# find contours on thresholded image`
`contours,nada = cv2.findContours(frame1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)`

`for c in contours:`

    `# contour data (from top left)`
    `x1,y1,w,h = cv2.boundingRect(c)`
    `if w < 65 or h < 65:`
        `continue` 
`x2,y2 = x1+w,y1+h`

`# percent area`
`percent = 100*w*h/750000`

`# if the contour is too small, ignore it`
`if percent < 0.2:`
        `continue`

`# if the contour is too large, ignore it`
`elif percent > 60:`
       ` continue`

`cv2.rectangle(frame0,(int(x1),int(y1)),(int(x2),int(y2)),(0,255,0),2)`

`img = frame1[y1:y2, x1:x2]`

`# display`
`cv2.namedWindow("Object Detection")`
`cv2.imshow("Object Detection",frame0)`

`# key delay and action`
`key = cv2.waitKey(1) & 0xFF`

`# esc ==  27 == quit`
`# q   == 113 == quit`
`if key in (27,113):`
    `cv2.waitKey(0)`    
    `cv2.destroyAllWindows()`

`cv2.waitKey(0)`

`cv2.destroyAllWindows()`

Hello, I have questions in solving problems. So i ask questions in this site.
I’ve been programming a little bit, but i don’t know how to measure the number of "C" shapes shown in the ‘picture’ per column.
if you know this problems, Any answer would be fine, so please leave an answer.
Thank you.

Source: Python Questions

LEAVE A COMMENT