Example #1
0
def extract_chars():
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-i", "--image", required=True, help="Path to the image")
    args = vars(ap.parse_args())

    # load the image and define the window width and height
    image = cv2.imread(args["image"])
    (winW, winH) = (192, 192)

    # loop over the image pyramid
    for resized in pyramid(image, scale=1.5):
        # loop over the sliding window for each layer of the pyramid
        for (x, y, window) in sliding_window(resized,
                                             stepSize=32,
                                             windowSize=(winW, winH)):
            # if the window does not meet our desired window size, ignore it
            if window.shape[0] != winH or window.shape[1] != winW:
                continue

            import pytesseract
            #print(pytesseract.image_to_string(window))

            with open('extracted_info.txt', 'a') as info_file:
                info_file.write(
                    pytesseract.image_to_string(window).encode('utf-8') + '\n')
                info_file.write('#\n')

            clone = resized.copy()
            cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
            cv2.imshow("Window", clone)
            cv2.waitKey(1)
            time.sleep(0.025)
img_path = '/Users/nihaar/Documents/4yp/4yp/code/sliding-window/img_sweep39_normalised.mat'
# load the image and define the window width and height
# image = cv2.imread(args["image"])
neg_mat1 = scio.loadmat(img_path)
image = neg_mat1['imgnormali']

(winW, winH) = (36, 36)
# angle = (0,45,90,135)
# image = image[:,:,1]
# image = image/128
ori = orientations(image)
detections = np.empty((0,2))

for i in ori:
	# loop over the image pyramid
	for resized in pyramid(i, scale=1.5):
		# loop over the sliding window for each layer of the pyramid
		for (x, y, window) in sliding_window(resized, stepSize=10, windowSize=(winW, winH)):
			# if the window does not meet our desired window size, ignore it
			if window.shape[0] != winH or window.shape[1] != winW:
				continue

			# THIS IS WHERE YOU WOULD PROCESS YOUR WINDOW, SUCH AS APPLYING A
			# MACHINE LEARNING CLASSIFIER TO CLASSIFY THE CONTENTS OF THE
			# WINDOW
			# x_test1 = 
			# loaded_model = cPickle.load(open('~/svm-classifier.pkl', 'rb'))
			# y_score = loaded_model.decision_function(x_test1)
			
			window = np.reshape(window,[1,36,36,1])
			# window = np.reshape(window,[-1,1681])
from pyimagesearch.helpers import sliding_window
import argparse
import time
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())

# load the image and define the window width and height
image = cv2.imread(args["image"])
(winW, winH) = (128, 128)

# loop over the image pyramid
for resized in pyramid(image, scale=1.5):
    # loop over the sliding window for each layer of the pyramid
    for (x, y, window) in sliding_window(resized,
                                         stepSize=32,
                                         windowSize=(winW, winH)):
        # if the window does not meet our desired window size, ignore it
        if window.shape[0] != winH or window.shape[1] != winW:
            continue

        # THIS IS WHERE YOU WOULD PROCESS YOUR WINDOW, SUCH AS APPLYING A
        # MACHINE LEARNING CLASSIFIER TO CLASSIFY THE CONTENTS OF THE
        # WINDOW

        # since we do not have a classifier, we'll just draw the window
        clone = resized.copy()
        cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
Example #4
0
    # apply non-maxima suppression to suppress weak, overlapping bounding
    # boxes
    boxes = non_max_suppression(np.array(rects), probs=confidences)

    # loop over the bounding boxes
    for (startX, startY, endX, endY) in boxes:
        # scale the bounding box coordinates based on the respective
        # ratios
        startX = int(startX * rW)
        startY = int(startY * rH)
        endX = int(endX * rW)
        endY = int(endY * rH)

        # draw the bounding box on the image
        cv2.rectangle(imag, (startX, startY), (endX, endY), (0, 255, 0), 2)

    # show the output image
    cv2.imshow("Text Detection", imag)
    cv2.waitKey(0)
    #time.sleep(1)


for resized in pyramid(image,scale=2):
    for (x,y,window) in sliding_window(resized, stepSize=32, windowSize=(winW,winH)):
        if window.shape[0] != winH or window.shape[1]!= winW:
            continue
        east(window)
        clone = resized.copy()
        cv2.rectangle(clone, (x,y), (x + winW, y + winH), (0,255,0), 2)
        cv2.imshow("window", clone)
        time.sleep(0.025) 
Example #5
0
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
stepSize = 0
# load the image and define the window width and height
image = cv2.imread(args["image"], cv2.IMREAD_GRAYSCALE)
img = np.asarray(image)
#p = img.shape
#print (p)
# imread loads the image
(winW, winH) = (80, 80)

#Sliding window size
# loop over the image pyramid
for a in range(0, 2):
    for b in range(0, 2):
        for resized in pyramid(image):
            # loop over the sliding window for each layer of the pyramid
            for (x, y, window) in sliding_window(resized,
                                                 stepSize=24,
                                                 windowSize=(winW, winH)):
                # if the window does not meet our desired window size, ignore it
                # or check for the boundary conditions step2 and check if the pixel is grey or not step1 and then
                #calculate the ratio.
                if window.shape[0] != winH or window.shape[1] != winW:
                    continue
                    #stepSize=stepSize-10
                    #winW = winW - 20
                    #winH = winH - 20
                '''
				Classifier for images that are required, is to be inserted here.
				Like for tick marks and comments that ae to be detected.
Example #6
0
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
ap.add_argument("-s",
                "--scale",
                type=float,
                default=1.5,
                help="scale factor size")
args = vars(ap.parse_args())

# load the image
image = cv2.imread(args["image"])

# METHOD #1: No smooth, just scaling.
# loop over the image pyramid
for (i, resized) in enumerate(pyramid(image, scale=args["scale"])):
    # show the resized image
    cv2.imshow("Layer {}".format(i + 1), resized)
    cv2.waitKey(0)

# close all windows
cv2.destroyAllWindows()

# METHOD #2: Resizing + Gaussian smoothing.
for (i, resized) in enumerate(pyramid_gaussian(image, downscale=2)):
    # if the image is too small, break from the loop
    if resized.shape[0] < 30 or resized.shape[1] < 30:
        break

    # show the resized image
    cv2.imshow("Layer {}".format(i + 1), resized)
Example #7
0
#from pyima/Users/Owner/Downloads/sliding-windowgesearch.helpers import sliding_window
import argparse
import time
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())

# load the image and define the window width and height
image = cv2.imread(args["image"])
(winW, winH) = (128, 128)

# loop over the image pyramid
for resized in pyramid(image, scale=1.5):
	# loop over the sliding window for each layer of the pyramid
	for (x, y, window) in sliding_window(resized, stepSize=32, windowSize=(winW, winH)):
		# if the window does not meet our desired window size, ignore it
		if window.shape[0] != winH or window.shape[1] != winW:
			continue

		# THIS IS WHERE YOU WOULD PROCESS YOUR WINDOW, SUCH AS APPLYING A
		# MACHINE LEARNING CLASSIFIER TO CLASSIFY THE CONTENTS OF THE
		# WINDOW

		# since we do not have a classifier, we'll just draw the window
		clone = resized.copy()
		cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
		cv2.imshow("Window", clone)
		cv2.waitKey(1)