def tracker(i): boxes = Boxes(len(files)) tex = Texture() ims = Slicer() th = Threshold() hog = Hog() cells = Cells(sizeh, sizew) names = list(listdir(path)) names = names[i:i + batch_size] net = Network() net.load('data/net/dataset_184_nets_ann/', 'compile_config.txt', hog_block_size, hog_cell_size, hog_orientations) index = 0 while (len(names) > 0): index = len(names) - 1 name = names.pop() img = cv2.imread(path + name) img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) images, coords = ims.split(img_grey, sizeh, sizew, sizeh, sizew) signal = tex.analize(images, haralick_feature) indexes = th.threshold_mean(signal) #coords_f = [] #for x in indexes: # coords_f.append(coords[x]) coords = coords[indexes] coords = cells.group(coords) coords = cells.reorganize_coords(coords) for c in coords: part_img = img_grey[c[2]:c[3], c[0]:c[1]] part_img = cv2.resize(part_img, resize_img) part = hog.runOne(part_img, orient=hog_orientations, pixels=hog_cell_size, cells=hog_block_size) part = part.reshape((1, part.shape[0])) Y = net.predict(part)[0, 0] if (Y > thresh and c[0] != 0 and c[1] != 500 and abs(c[0] - c[1]) * abs(c[2] - c[3]) > 625): cells.box2(img, c) box = Box() box.box = [c[0], c[2], c[1], c[3]] boxes.add(index, box) cv2.imwrite(path_out + name, img) boxes.save('boxes_predicted_ann_25.b')
def tracker(i): boxes = Boxes(len(files)) tex = Texture() ims = Slicer() th = Threshold() hog = Hog() cells = Cells(sizeh,sizew) names = list(listdir(path)) names = names[i:i+batch_size] f = open('data/net/dataset_184_nets_svm/svm_c_2_p_8_o_2.svm','rb') clf = pickle.load(f) f.close() while(len(names)>0): index = len(names)-1 name = names.pop() img = cv2.imread(path+name) img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) images,coords = ims.split(img_grey,sizeh,sizew,sizeh,sizew) signal_p = tex.analize(images,haralick_feature) indexes = th.threshold_mean(signal_p) coords_f = [] for x in indexes: coords_f.append(coords[x]) coords = cells.group(coords_f) coords = cells.reorganize_coords(coords) for c in coords: part_img = img_grey[c[2]:c[3],c[0]:c[1]] part_img = cv2.resize(part_img,resize_img) part = hog.runOne(part_img,orient=hog_orientations,pixels=hog_cell_size,cells=hog_block_size) part = part.reshape((1,part.shape[0])) Y = clf.predict(part) if(Y>thresh and c[0]!=0 and c[1]!=500 and abs(c[0]-c[1])*abs(c[2]-c[3])>625 ): cells.box2(img,c) box = Box() box.box = [c[0],c[2],c[1],c[3]] boxes.add(index,box) cv2.imwrite(path_out+name,img) boxes.save('boxes_predicted_svm_25.b')
def tracker(i): boxes = Boxes(len(files)) tex = Texture() ims = Slicer() th = Threshold() cells = Cells(sizeh,sizew) names = list(listdir(path)) names = names[i:i+batch_size] f = open('svmsemhog.svm','rb') clf = pickle.load(f) f.close() while(len(names)>0): index = len(names)-1 name = names.pop() img = cv2.imread(path+name) img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) images,coords = ims.split(img_grey,sizeh,sizew,sizeh,sizew) signal_p = tex.analize(images,haralick_feature) indexes = th.threshold_mean(signal_p) coords_f = [] for x in indexes: coords_f.append(coords[x]) coords = cells.group(coords_f) coords = cells.reorganize_coords(coords) for c in coords: part_img = img_grey[c[2]:c[3],c[0]:c[1]] part_img = cv2.resize(part_img,resize_img).flatten() print(part_img) input() Y = clf.predict(part_img) if(Y>thresh and c[0]!=0 and c[1]!=500 and abs(c[0]-c[1])*abs(c[2]-c[3])>625 ): cells.box2(img,c) box = Box() box.box = [c[0],c[2],c[1],c[3]] boxes.add(index,box) cv2.imwrite(path_out+name,img) boxes.save('boxes_predicted_svm.b')
tex = Texture() ims = Slicer() th = Threshold() img = cv2.imread("000475.jpg") img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) images, coords = ims.split(img, 50, 50, 50, 50) '''i=0 for img in images: if(i%2==0): cv2.rectangle(img, (0,0),(50,50), (225,105,65), 2) cv2.imwrite('img'+str(i)+'.jpg',img) i+=1''' l = tex.analize(images, 3) mean_l = statistics.mean(l) std_l = statistics.stdev(l) print(mean_l) print(std_l) x = list(range(0, len(l))) top = max(l) - mean_l plt.plot(x, l, linestyle='-', marker='o', color='c') plt.plot(x, len(l) * [mean_l], 'g')
slicer = Slicer() tex = Texture() ths = Threshold() img_p = cv2.imread("data/frames/frames0/000235.jpg") img_n = cv2.imread("data/frames/frames0/000270.jpg") imgs_p, coords = slicer.split(img_p, 25, 25, 25, 25) imgs_n, coords = slicer.split(img_n, 25, 25, 25, 25) # 1 - energia # 2 - entropia # 3 - correlação # 5 - inércia signal_p = tex.analize(imgs_p, 1)[1:] media_p = media(signal_p) #signal_p = transform(signal_p,media_p) #media_p = media(signal_p) #signal_p = transform(signal_p,media_p) #signal_n = tex.analize(imgs_n,3)[1:] #media_n = media(signal_n) #signal_n = transform(signal_n,media_n) #media_n = media(signal_n) #signal_n = transform(signal_n,media_n) x = range(len(signal_p)) #plt.subplot(121) #plt.plot(x,[media_p]*len(signal_p),'-r')