appDataset15 = open(os.path.join(dataDest,"appearance15.p") ,'wb') label15 = open(os.path.join(dataDest, "label15.p"), 'wb') paths = flags.path.split(',') for path in paths: imgs = os.listdir(path) gt_path = path + '_gt' gts = os.listdir(gt_path) if '.DS_Store' in imgs: imgs.remove('.DS_Store') gts.remove('.DS_Store') for i in range(len(imgs)): obs_img_path = os.path.join(path, imgs[i]) image = cv2.imread(obs_img_path, 0) gt = cv2.imread(os.path.join(gt_path, gts[i]), 0) img_resized = cv2.resize(image, (240, 165), interpolation=cv2.INTER_LINEAR) gt_resized = cv2.resize(gt, (240, 165), interpolation=cv2.INTER_LINEAR) img_slides = mylib.sliding_window(img_resized, stepSize=15, windowSize=(15, 15)) gt_slides = mylib.sliding_window(gt_resized, stepSize=15, windowSize=(15, 15)) for (x, y, slide) in img_slides: (x, y, gt_slide) = next(gt_slides) gt_slide = gt_slide.flatten() if mylib.zero_fraction(gt_slide) != 1: pickle.dump(1, label15) else : pickle.dump(0, label15) slide = slide.flatten() slide = cv2.normalize(slide.astype(float), slide.astype(float), alpha=0, beta=1, norm_type=cv2.NORM_MINMAX) pickle.dump(slide, appDataset15)
interpolation=cv2.INTER_LINEAR) # resized = resizeToMainWindowSize(image,240, 165) elif sz == 18: resized = cv2.resize( image, (252, 162), interpolation=cv2.INTER_LINEAR) # resized = resizeToMainWindowSize(image,252, 162) elif sz == 20: resized = cv2.resize( image, (240, 160), interpolation=cv2.INTER_LINEAR) # resized = resizeToMainWindowSize(image,240,160) for (x, y, window) in mylib.sliding_window(resized, stepSize=15, windowSize=(tz, tz)): # if the window does not meet our desired window size, ignore it # if window.shape[0] != winH or window.shape[1] != winW: if window.shape[0] != sz or window.shape[1] != sz: continue clone = resized.copy() # cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2) cv2.rectangle(clone, (x, y), (x + sz, y + sz), (0, 255, 0), 1) cv2.imshow("Image", image) cv2.imshow("Clone", clone) cv2.imshow("window", window)
cv2.imwrite( str(tmppath) + "/optframe/" + str(index + 1) + "_" + str(file.split('.')[0]) + ".jpeg", rgbImg) cv2.imwrite( str(tmppath) + "/optgrayframe/" + str(index + 1) + "_" + str(file.split('.')[0]) + ".jpeg", motionGray) # Here display the optical flow in the image mylib.dispOpticalFlow(prevFrame, flow, 10, 'Optical flow') winNo = 0 rgbImg = cv2.resize(rgbImg, (240, 165), 1) motionGray = cv2.resize(motionGray, (240, 165), 1) for (x, y, window) in mylib.sliding_window(rgbImg, stepSize=15, windowSize=(15, 15)): if not os.path.exists(os.path.join(tmppath, "wincolor")): os.makedirs(os.path.join(tmppath, "wincolor")) if window.shape[0] != winH or window.shape[1] != winW: print winNo #cv2.imshow("Internal window", window) continue clone = rgbImg.copy() clone1 = motionGray.copy() cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2) cv2.rectangle(clone1, (x, y), (x + winW, y + winH), (0, 255, 0), 2) cv2.startWindowThread()