from pyclustering.nnet.som import som, type_conn, type_init, som_parameters from ann.function.sompy import SOMFactory import numpy as np import pandas as pd import glob import os # 1. load image img = cv.imread('C:/flashwoman/Object-detection/EyeCandy/img/img_book_only.png') img_org = cv.imread('C:/flashwoman/Object-detection/EyeCandy/img/bookshelf_04.jpg') # 2. preprocess images img = preprocessing(img) img, rect = contours(img,img_org) # 3. bring mid coordinates coord = [] for i in range(len(rect)): # extracting colour by using mid-coordinates of the book x = (list(rect[i][0])[0] + list(rect[i][1])[0])/2 y = (list(rect[i][0])[1] + list(rect[i][1])[1])/2 coord.append([x, y]) print('book_mid_coordinates :\n', coord) # 4. get 'bgr' from coordinates bgr_val = [] for i in range(len(coord)): ## 1. x, y 좌표값 받아오기
path = 'C:/flashwoman/EyeCandy/img/source/detect-bookshelf/origin/bookshelf_03.jpg' img_color = cv.imread(path) display('img_color', img_color) img_gray = cv.cvtColor(img_color, cv.COLOR_BGR2GRAY) display('img_gray', img_gray) # deal with no-background colors ret, thresh = cv.threshold(img_gray, 127, 255, cv.THRESH_BINARY) display('sep_threshold', thresh) img_color = preprocessing(img_color, 3, 3) img_write('1_thresh', img_color) # deal with similar-background colors ret, thresh = cv.threshold(img_gray, 127, 255, cv.THRESH_BINARY_INV) # display('sep_threshold', thresh) # img_color = preprocessing(img_color) # img_write('2_thresh', img_color) # do contour path = 'C:/flashwoman/Object-detection/EyeCandy/img/img_book_only.png' img_book_only = cv.imread(path) img_book_only = preprocessing(img_book_only) img_color = contours(img_book_only, img_color) img_write('3_contour', img_color) # do watershed img_watershed = watershed(img_color) display('watershed img', img_watershed) img_write('watershed', img_watershed) cv.destroyAllWindows()