mercredi 10 février 2021

How to separate blurry images and consider other images in the loop

I am reading images in for loop and trying to separate blurry & nonblurry images for the next steps of the image processing.

I have calculated the blurry images but how do I skip those images if they are blurry and consider only non-blurry images in the loop?

def model_predict2(img_location, defect_cp):
    file_list = glob.glob(os.path.join(img_location,'*')) 
    print("Number of images found: ", len(file_list))
    # Load the model
    defect_model = models.load_model(defect_cp)

    print("Finished loading the model")
    i=0
    blur_count = 0
    for img_file in file_list: 
        
        image = read_image_bgr(img_file)

        print("------------------------------------------------------------------")
        print("Processing image : ", img_file)

        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        variance_of_laplacian = cv2.Laplacian(gray, cv2.CV_64F).var()

        FOCUS_THRESHOLD = 2000
        if variance_of_laplacian < FOCUS_THRESHOLD:
            cv2.imwrite(os.path.join(blurry_img_loc, img_file.split('/')[-1]), image) 
            blur_count += 1

        else:
            continue

        #choose non blurry images only
        draw = image.copy()
        draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
        
        image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

Aucun commentaire:

Enregistrer un commentaire