def FFT_blur(img, thresh=27, vis=False, test=False): ''' thresh: blur or not judge level vis: test: for testing purpose, we can progressively blur our input image and conduct FFT-based blur detection on each example. This flag indicates whether to test or not. ''' # load the image, resize, convert to grayscale orig = cv2.imread(img) orig = imutils.resize(orig, width=500) gray = cv2.cvtColor(orig, cv2.COLOR_BGR2GRAY) # apply blur one by FFT (mean, blurry) = detect_blur_fft(gray, size=60) # size, thresh, vis # draw on the image, indicating where or not it is blurry image = np.dstack([gray] * 3) color = (0, 0, 255) if blurry else (0, 255, 0) text = 'Blurry {:.4f}' if blurry else 'Not Blurry ({:.4f})' text = text.format(mean) cv2.putText(image, text, (10, 25), cv2.FONT_HERSHEY_SIMPLEX, .7, color, 2) if not test: print('[INFO] {}'.format(text)) # show the output image cv2.imshow('Output', image) mac_show_cv2() # check to see if are going to test our FFT blurriness detector using various size of a Gaussian Kernel if test: # loop over various blur radii for radius in range(1, 30, 2): # clone the original grayscale image image = gray.copy() # check to see if the kernel radius is greater than zero if radius > 0: # blur the input image by the supplied radius using a Gaussian kernel image = cv2.GaussianBlur(image, (radius, radius), 0) # apply our blur detctor using the FFT (mean, blurry) = detect_blur_fft(image, size=60, thresh=thresh) # draw on the image, indicating whet2her or not it is blurry image = np.dstack([image] * 3) color = (0, 0, 255) if blurry else (0, 255, 0) text = 'Blurry ({:.4f})' if blurry else 'Not Blurry ({:.4f})' text = text.format(mean) cv2.putText(image, text, (10, 25), cv2.FONT_HERSHEY_SIMPLEX, .7, color, 2) print('[INFO] Kernel: {}, Result: {}'.format(radius, text)) # show the image cv2.imshow('Test Image', image) mac_show_cv2()
default=-1, help="whether or not we should progressively blur the image") args = vars(ap.parse_args()) # load the input image from disk, resize it, and convert it to # grayscale # orig = cv2.imread(args["image"]) orig = urlToImage( "https://www.sony.com.ec/image/bc6d25fa6371c2899ce704a2bed7614c?fmt=png-alpha&wid=960" ) orig = imutils.resize(orig, width=500) gray = cv2.cvtColor(orig, cv2.COLOR_BGR2GRAY) # apply our blur detector using the FFT (mean, blurry) = detect_blur_fft(gray, size=60, thresh=args["thresh"], vis=args["vis"] > 0) # draw on the image, indicating whether or not it is blurry image = np.dstack([gray] * 3) color = (0, 0, 255) if blurry else (0, 255, 0) text = "Blurry ({:.4f})" if blurry else "Not Blurry ({:.4f})" text = text.format(mean) cv2.putText(image, text, (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2) print("[INFO] {}".format(text)) # show the output image cv2.imshow("Output", image) cv2.waitKey(0) # check to see if are going to test our FFT blurriness detector using
# initialize the video stream and allow the camera sensor to warm up print("[INFO] starting video stream...") vs = VideoStream(src=0).start() time.sleep(2.0) # loop over the frames from the video stream while True: # grab the frame from the threaded video stream and resize it # to have a maximum width of 400 pixels frame = vs.read() frame = imutils.resize(frame, width=800, height=500) # convert the frame to grayscale and detect blur in it gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) (mean, blurry) = detect_blur_fft(gray, size=60, thresh=args["thresh"], vis=False) # draw on the frame, indicating whether or not it is blurry color = (0, 0, 255) if blurry else (0, 255, 0) text = "Blurry ({:.4f})" if blurry else "Not Blurry ({:.4f})" text = text.format(mean) cv2.putText(frame, text, (30, 70), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2) # show the output frame cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break