if cmd_subfolder not in sys.path: sys.path.insert(0, cmd_subfolder) import image_utils as utils import image_transform as transform ap = argparse.ArgumentParser( description= "(Personal peeve) Unwarp a presentation image click at a meeting") ap.add_argument("-i", "--image", required=True, help="Path to image file") args = vars(ap.parse_args()) image = cv2.imread(args["image"]) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cnts = utils.get_contours(gray) cnt = max(cnts, key=cv2.contourArea) hull = cv2.convexHull(cnt) # cv2.drawContours(image,[hull],0, (255,0,0),2) # cv2.imshow("Outline", image) # cv2.waitKey() rect = cv2.minAreaRect(hull) box = np.int0(cv2.boxPoints(rect)) # cv2.drawContours(image,[box],0, (0,0,255),2) # cv2.imshow("Outline", image) # cv2.waitKey() approx = cv2.approxPolyDP(hull, 0.02 * cv2.arcLength(hull, True), True)
cmd_subfolder = os.path.realpath( os.path.abspath(os.path.join(os.path.split(inspect.getfile(inspect.currentframe()))[0], "..","..", "Image_Lib"))) if cmd_subfolder not in sys.path: sys.path.insert(0, cmd_subfolder) import image_utils as utils import image_transform as transform ap = argparse.ArgumentParser(description="(Personal peeve) Unwarp a presentation image click at a meeting") ap.add_argument("-i", "--image", required=True, help="Path to image file") args = vars(ap.parse_args()) image = cv2.imread(args["image"]) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cnts = utils.get_contours(gray) cnt = max(cnts, key=cv2.contourArea) hull = cv2.convexHull(cnt) # cv2.drawContours(image,[hull],0, (255,0,0),2) # cv2.imshow("Outline", image) # cv2.waitKey() rect = cv2.minAreaRect(hull) box = np.int0(cv2.boxPoints(rect)) # cv2.drawContours(image,[box],0, (0,0,255),2) # cv2.imshow("Outline", image) # cv2.waitKey()
return morph.astype(np.uint8) ap = argparse.ArgumentParser("Finds contour of foot") ap.add_argument("-i", "--image", required=True, help="Path to image file") ap.add_argument("-bg", "--background", required=True, help="Path to background file") args = vars(ap.parse_args()) image = cv2.imread(args["image"]) background = cv2.imread(args["background"]) equlize = cv2.equalizeHist image_gray = (cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)) background_gray = (cv2.cvtColor(background, cv2.COLOR_BGR2GRAY)) img_cnts = utils.get_contours(image_gray, param = 75) bg_cnts = utils.get_contours(background_gray, param=75) image_edges = cv2.drawContours(np.zeros_like(image_gray), img_cnts, -1, 255, 2) bg_edges = cv2.drawContours(np.zeros_like(background_gray), bg_cnts, -1, 255, 2) show_image(image_edges, bg_edges, "Edges") output_diff = image_edges - bg_edges # cv2.absdiff(image_edges, bg_edges) output_diff[output_diff < 128] = 0 output_diff[output_diff > 128] = 255 kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) morphed = morph_close(output_diff, kernel1) kernel2 = cv2.getStructuringElement(cv2.MORPH_RECT, (11, 3)) morphed = cv2.morphologyEx(morphed, cv2.MORPH_CLOSE, kernel2) morphed = cv2.erode(morphed, kernel1) cv2.imshow("Eroded", morphed)