def main(): ap = argparse.ArgumentParser() ap.add_argument("-i1", "--image1", required=True, help="Path to the checkboard_image") ap.add_argument("-i2", "--image2", required=True, help="Path to the arm_spread_image") ap.add_argument("-i3", "--image3", required=True, help="Path to the waist_image") ap.add_argument("-a", "--affine_mode", required=True, help="To perform Affine Corrections") args = vars(ap.parse_args()) # load the image, clone it, and setup the mouse callback function image = cv2.imread(args["image1"]) arm_spread_image = cv2.imread(args["image2"]) waist_image = cv2.imread(args["image3"]) affine_correct_flag = (args["affine_mode"]) metre_pixel_x, metre_pixel_y, coordinate, affine_correct_parameters = analyze_chessboard( image, affine_correct_flag) segmented_image = segment.segmenter(image) print "Segmentation Completed 1" segmented_arm_image = segment.segmenter(arm_spread_image) print "Segmentation Completed 2" cv2.imwrite("first.jpg", segmented_image) cv2.imwrite("second.jpg", segmented_arm_image) block_cut = np.zeros(segmented_image.shape) block_cut[coordinate[0][1]:coordinate[1][1], coordinate[0][0]:coordinate[1][0]] = 1 # segmented_image=segmented_image*block_cut if (affine_correct_flag == 'True'): arm_spread_image = affine_correct(arm_spread_image, affine_correct_parameters) waist_image = affine_correct(waist_image, affine_correct_parameters) segmented_image = affine_correct(segmented_image, affine_correct_parameters) print "Affine Corrected" # detect_wrist(segmented_arm_image) # cv2.imwrite("affine_corrected.jpg",segmented_image) measure_distance(segmented_image, segmented_arm_image, arm_spread_image, waist_image, image, metre_pixel_x, metre_pixel_y)
def main(): ap = argparse.ArgumentParser() ap.add_argument("-i1", "--image1", required=True, help="Path to the checkboard_image") ap.add_argument("-i2", "--image2", required=True, help="Path to the arm_spread_image") ap.add_argument("-i3", "--image3", required=True, help="Path to the waist_image") ap.add_argument("-a", "--affine_mode", required=True, help="To perform Affine Corrections") args = vars(ap.parse_args()) image = cv2.imread(args["image1"]) arm_spread_image = cv2.imread(args["image2"]) waist_image = cv2.imread(args["image3"]) affine_correct_flag = (args["affine_mode"]) metre_pixel_x, metre_pixel_y, coordinate, affine_correct_parameters = analyze_chessboard( image, affine_correct_flag) segmented_image = segment.segmenter(image) segmented_arm_image = segment.segmenter(arm_spread_image) a = cv2.imwrite("first.jpg", segmented_image) b = cv2.imwrite("second.jpg", segmented_arm_image) block_cut = np.zeros(segmented_image.shape) block_cut[coordinate[0][1]:coordinate[1][1], coordinate[0][0]:coordinate[1][0]] = 1 if (affine_correct_flag == 'True'): arm_spread_image = affine_correct(arm_spread_image, affine_correct_parameters) waist_image = affine_correct(waist_image, affine_correct_parameters) segmented_image = affine_correct(segmented_image, affine_correct_parameters) measure_distance(segmented_image, segmented_arm_image, arm_spread_image, waist_image, image, metre_pixel_x, metre_pixel_y)
def read_data(src_dir, training): tags = [] articles = [] for dir_path, dir_names, file_names in os.walk(src_dir): for filename in file_names: file_path = os.path.join(dir_path, filename) with open(file_path, 'r') as f: text = f.read() segs = segmenter(text) article = " ".join(del_stops(segs)) article = del_stops(segs) if training: tag = dir_path.split("/")[-1] tags.append(tag) articles.append(article) if training: assert len(tags) == len(articles) tags_list = ["dry", "normal", "oily"] return (tags, articles, tags_list)
import tkinter as tk import cv2 from segment import segmenter from tkinter import filedialog root = tk.Tk() root.withdraw() file_path = filedialog.askopenfilename() image_to_segment = cv2.imread(file_path) segmenter(image_to_segment)
from sklearn.model_selection import train_test_split # == Load data == print("Loading dataset...") files = os.listdir() D = [] # Label: # - dry: 0 # - normal: 1 # - oil: 2 y = np.array([]) print(len(D), " documents, ", len(y), " labels.") # == Chinese Segmentation == X = np.array([del_stops(segmenter(d)) for d in D]) # == Split dataset == X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) # == Vector Transformation == print("Extracting features from the dataset...") vectorizer = Pipeline([ ('vect', HashingVectorizer(n_features=(2**21), non_negative=True, lowercase=False)), ('tfidf', TfidfTransformer(norm='l2')), ]) if __name__ == '__main__': vectorizer.fit()
def main(): ap = argparse.ArgumentParser() ap.add_argument("-i1", "--image1", required=True, help="Path to the checkboard_image") ap.add_argument("-i2", "--image2", required=True, help="Path to the arm_spread_image") ap.add_argument("-i3", "--image3", required=True, help="Path to the waist_image") ap.add_argument("-a", "--affine_mode", required=True, help="To perform Affine Corrections") args = vars(ap.parse_args()) # load the image, clone it, and setup the mouse callback function image = cv2.imread(args["image1"]) image22 = np.copy(image) arm_spread_image = cv2.imread(args["image2"]) waist_image = cv2.imread(args["image3"]) affine_correct_flag = (args["affine_mode"]) metre_pixel_x, metre_pixel_y, coordinate, affine_correct_parameters = analyze_chessboard( image, affine_correct_flag) segmented_image = segment.segmenter(image) print "Segmentation Completed 1" segmented_arm_image = segment.segmenter(arm_spread_image) print "Segmentation Completed 2" image2 = affine_correct(image, affine_correct_parameters) image2 = cv2.rectangle(image2, (coordinate[0][0], coordinate[0][1]), (coordinate[1][0], coordinate[1][1]), (255, 0, 0), 3) block_cut = np.zeros(segmented_image.shape) block_cut[coordinate[0][1]:coordinate[1][1], coordinate[0][0]:coordinate[1][0]] = 1 segmented_image = segmented_image * block_cut if (affine_correct_flag == 'True'): image2 = affine_correct(image, affine_correct_parameters) cv2.imwrite('affine_correction_3.jpg', np.concatenate((image, image2), axis=1)) arm_spread_image = affine_correct(arm_spread_image, affine_correct_parameters) waist_image = affine_correct(waist_image, affine_correct_parameters) segmented_image = affine_correct(segmented_image, affine_correct_parameters) print "Affine Corrected" measure_distance(segmented_image, segmented_arm_image, arm_spread_image, waist_image, image22, metre_pixel_x, metre_pixel_y)