Python + OpenCV: Enumerate Matrix -


i newbie python.

and want access mat (a threshold binary image) element opencv , create histogram according x-axis, , can image segmentation vertically.

what have done preprocess image , enumerate twice following.

def crack(src):     #src binary image       src = cv2.resize(src, (0,0), fx=6, fy=6)     thresh = preprocessing(src)      #create empty histogram     print(thresh.shape)     height, width = thresh.shape     size = height ,255,  3     hist = np.zeros(size, dtype=np.uint8)      #enumerate elements     y, x in enumerate(thresh):         val = 0         x, pix in enumerate(x):             val = val+ pix/255             print y,x, val         cv2.rectangle(hist, (y, 255-val), (y+val, 255-val+1), (0, 255, 0), 1)      cv2.imshow("thresh", thresh)     cv2.imshow("hist", hist) 

and if directly enumerate threshold mat like

    y, x in enumerate(thresh): 

i can enumerate outer y axis first enumerate x axis. how can reversely? aim image this:

image1 http://7xsnr6.com2.z0.glb.clouddn.com/qq%e5%9b%be%e7%89%8720160509184009.jpg

image references:

jeff yan, a low-cost attack on microsoft captcha

if want number of black pixels each x position, following code should work:

# enumerate elements x in range(width):     val = 0     y in range(height):         val += (255-thresh[y, x])/255         print y, x, val     cv2.line(thresh, (x, height-val-1), (x, height-1), (0, 255, 0), 1) 

so looping on x axis and, each of position, finding amount of black pixels on y axis, stored in variable val. draw line has height equal val pixels @ x position looping starts @ bottom of image.

hope helped!


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -