예제 #1
0
def main():
    # global parameters
    original_image_name = [
        "01_225x255.jpg", "02_272x272.jpg", "03_300x300.jpg", "04_381x378.jpg",
        "05_500x500.jpg", "06_630x475.jpg"
    ]

    images_folder = './images/'

    # starts procedure
    print 'Procedure sarted'

    # overall stats file
    m = open(images_folder + 'overall_stats.txt', 'w')

    # identify image regions using connected components algorithm
    for a in range(len(original_image_name)):
        lista = []
        f = open(images_folder + original_image_name[a] + '_stats.txt', 'w')
        print >> f, original_image_name[a]
        print original_image_name[a]

        pi = ProcessImage(images_folder + original_image_name[a])

        for i in range(100):

            # record start time
            start = time.clock()

            # identify images
            pi.identify_labels()

            # record end time
            end = time.clock()

            # add time spent to list
            lista.append(end - start)
            pass
        pass

        # not background pixels
        print >> f, pi.get_not_background_pixels()

        # save image
        pi.save_image()

        # print stats to file
        i = 1
        for row in lista:
            print >> f, '%d|%r' % (i, row)
            i = i + 1
        pass

        # calculate mean
        mean = sum(lista) / len(lista)
        print >> m, '%d|%r' % (pi.get_not_background_pixels(), mean)
    pass

    # Ends procedure
    print 'Procedure ended'
    def do_the_thing(filename, account_number='016210003383', amount=2500):
        process_image = ProcessImage(image_file=filename)
        thresholded_image = process_image.get_processed_image()

        extract_characters = ExtractCharacters(
            thresholded_image=thresholded_image)
        parsed_text = extract_characters.extract()

        # print(parsed_text)
        check_slip = CheckSlip(parsed_text=parsed_text)
        account_verified = check_slip.check_account_number(
            account_number=account_number)
        amount_verified = check_slip.check_payment(amount=amount)
        transaction_number, confidence = check_slip.check_transaction_number()

        # cv2.imshow('thresholded image', thresholded_image)
        # cv2.waitKey(0)
        # cv2.destroyAllWindows()

        return {
            'account_verified': account_verified,
            'amount_verified': amount_verified,
            'transaction_number': transaction_number,
            'confidence': confidence
        }
예제 #3
0
def pre_process_image(img_path):

    process_img = ProcessImage(img_path)

    image = process_img.read_image()
    plt.imshow(image)
    process_img.apply_gaussian_blur((5, 5))
    edges = process_img.apply_canny_edge_detection(40, 120)
    plt.imshow(edges)
    maksed_img = process_img.apply_mask_to_img()
    plt.imshow(maksed_img)
    return image, edges, maksed_img
예제 #4
0
 def __init__(self, test_file, train, threshold):
     self.test_file = test_file
     #compute probability for test data
     self.test = ProcessImage(self.test_file)
     self.test.loadImg()
     print "test image size:"
     print self.test.getImgSize()
     self.N = self.test.width * self.test.height
     self.train = train
     self.gauss_threshold = threshold
     self.lower_bound = 1.0 / 3.0
     self.upper_bound = 2.0 / 3.0
     self.extractLetters()
예제 #5
0
 def __init__(self, num):
     self.samples = []
     self.num = num
     self.tot_mean = [0.0, 0.0, 0.0]
     self.tot_std = [0.0, 0.0, 0.0]
     #lets' go through all sample inputs and extract their distributions
     for i in range(1, num + 1):
         sample_file = "buses/sample_" + str(i) + ".jpg"
         #sample_file = "../buses/boundary.jpg"
         sample = ProcessImage(sample_file)
         print "train image size:"
         print sample.getImgSize()
         #load training data for bus head sign
         sample.loadImg()
         self.samples.append(sample)
     self.computeTotMean()
     self.computeTotStd()
예제 #6
0
    def __init__(self):
        # Global variables for executions
        self._title_exam = ''
        self._path_dataset_out = ''

        # Dependences
        self._process = ProcessImage()
        self._pupil = Pupil()
        self._eye = Eye()

        # Limit cash dependences
        self._max_execution_with_cash = 20

        # Directoris
        self._projects_path = '/media/marcos/Dados/Projects'

        self._dataset_path = '{}/Datasets/exams'.format(self._projects_path)
        self._dataset_out = '{}/Results/PupilDeep/Frames'.format(
            self._projects_path)
        self._dataset_label = '{}/Results/PupilDeep/Labels'.format(
            self._projects_path)

        # Stops and executions
        self._frame_stop = 150
        self._frame_start = 100

        self._movie_stop = 0
        self._list_not_available = []
        self._list_available = [
            '25080325_08_2019_08_48_58', '25080425_08_2019_08_53_48'
        ]
        # self._list_available = ['25080325_08_2019_08_48_58', '25080425_08_2019_08_53_48', '25080425_08_2019_08_55_59', '25080425_08_2019_09_05_40', '25080425_08_2019_09_08_25']
        # self._list_available = ['new_benchmark']

        # Params color
        self._white_color = (255, 255, 0)
        self._gray_color = (170, 170, 0)

        # Params text and circle print image
        self._position_text = (30, 30)
        self._font_text = cv2.FONT_HERSHEY_DUPLEX
        self._size_point_pupil = 5

        # Params dataset labels out
        self._title_label = 'frame,center_x,center_y,radius,flash,eye_size,img_mean,img_std,img_median'
예제 #7
0
    def pupil_process(self, paths):
        pupil_deep = PupilDeep()
        process = ProcessImage()
        pupil = Pupil(pupil_deep)
        draw = DrawImages()
        # information = Information()

        self._path_label = paths['path_label']
        self._add_label(self._title_label)

        exam = cv2.VideoCapture(paths['path_exam'])
        fps = exam.get(cv2.CAP_PROP_FPS)

        # patient_exam, param_exam = information.get_information_exam(paths['path_information'], fps)

        number_frame = 0
        while True:
            _, frame = exam.read()

            if (frame is None) or ((self._frame_stop > 0) and (number_frame >= self._frame_stop)):
                break

            if (self._frame_start > 0) and (number_frame < self._frame_start):
                number_frame += 1
                continue

            original = np.copy(frame)
            img_orig_gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
            # self._save_images({'original': original}, number_frame, paths['path_out'])

            img_process, flash = process.process_image(original)
            # self._save_images({'process': img_process}, number_frame, paths['path_out'])

            img_mean, img_std, img_median = img_process.mean(), img_process.std(), np.median(img_process)

            center, radius, points, images, mean_binary = pupil.pupil_detect(img_process)

            # binary = images['binary_pre_process']
            # binary = draw.mark_center(binary, center)
            # binary = draw.draw_circles(binary, points, 2, self._white_color)
            # self._save_images({'binary': binary}, number_frame, paths['path_out'], center)

            img_process = draw.mark_center(img_process, center)
            img_process = draw.draw_circles(img_process, points, 2, self._white_color)
            img_process = draw.draw_circles(img_process, [(center[0], center[1])], radius, self._white_color)
            self._save_images({'img_process': img_process}, number_frame, paths['path_out'])

            # self._save_histogram(images['histogram'], number_frame, paths['path_out'])

            # img_presentation = cv2.hconcat([img_orig_gray, binary, img_process])

            # label = 'Frame=%d;Radius=%d;Center=(%d,%d);BinMean=(%f)' % (
            #     number_frame, radius, center[0], center[1], mean_binary)

            # self._show_image(img_presentation, label, number_frame, paths['path_out'])

            # flash_information, color_information = information.get_information_params(number_frame)

            params = ['patient_exam', 'param_exam', number_frame, center[0], center[1], radius, flash, 'flash_information',
                      'color_information', 0, img_mean, img_std, img_median]

            self._add_params_label(params)

            number_frame += 1

        cv2.destroyAllWindows()
        exam.release()
from process_image import ProcessImage
import lane_line_finding
from moviepy.editor import VideoFileClip

if __name__ == "__main__":
    cal = lane_line_finding.Calibration.create_calibration()
    pt = lane_line_finding.PerspectiveTransform.create_perspective_transform(
        0, 0, 0)

    video_name = "project_video.mp4"
    # video_name = "00_crop_project_video.mp4"

    pi = ProcessImage(pt, cal, smooth_window=5)
    project_output = '170527_0.5.1-project-output_{}'.format(video_name)

    clip = VideoFileClip("../" + video_name)
    project_clip = clip.fl_image(pi.run)
    project_clip.write_videofile(project_output, audio=False)
    print("Output video: {}".format(project_output))
예제 #9
0
 def __init__(self):
     self.process = ProcessImage(MIN_CONF_LEVEL, blur_level, FRAME_SIZE)
     self.action = Action()
     self.SKIP = False
     self.attempt = 1
     self.frame_with_no_face = 0