Python OpenCV divide image(shelf) into parts(shelves) -
my task find proper solution dividing image shelf horizontal parts (shelves). shelves different in color, size , can , can not contain objects on them.
for example these 2 shelves on images below have different spaces between each other , colors:
is there solution perform task different occasions? thinking applying sobel y gradient hough line transform, efficient different cases?
note, number of rows in shelf known before image processing, maybe helpful.
thanks information in advance!
answer:
for has similar task me sharing solution used.
first time thinking using lines rows division, not universal solution me. satisfactory result have recieved cv2.reduce. thereby can find horizontal or vertical graphs our image (in case horizontal graph).
after graph ready can write algorithm detect regions divided.
below code fragment apply reduce on image , visualise graph:
import cv2 matplotlib import pyplot plt image = cv2.imread('test6.jpg') gray = cv2.cvtcolor(image, cv2.color_bgr2gray) ret,th = cv2.threshold(gray,0,255,cv2.thresh_binary+cv2.thresh_otsu) reduced_h = cv2.reduce(th, 1, cv2.reduce_avg) index, line in enumerate(reduced_h): cv2.line(image, (0, index), (line[0], index), (0, 255, 0), 1) plt.imshow(cv2.cvtcolor(image, cv2.color_bgr2rgb)),plt.show() i able reach next result modified algorithm: 
you can discover code at repo.



Comments
Post a Comment