Пример #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)
Пример #2
0
def predictor(im, w, queue):
    global fea_det
    global step_size
    global k
    global voc
    global clf
    global classes_names
    global stdSlr
    global image_paths
    best = 0
    for (x_pt, y_pt, window) in sliding_window(im, stepSize=16, windowSize=(w,w)):
        if window.shape[0] != w or window.shape[1] != w:
            continue
        kpts = [cv2.KeyPoint(x, y, step_size) for y in range(0, window.shape[0], step_size)
                                              for x in range(0, window.shape[1], step_size)]
        (kpts, des) = fea_det.compute(window, kpts) # compute dense descriptors
        des = whiten(des)
        test_features = np.zeros((len(image_paths), k), "float32")
        words, L2distance = vq(des, voc)
        for wd in words:
            test_features[0][wd] += 1
        nbr_occurences = np.sum( (test_features > 0) * 1, axis = 0)
        idf = np.array(np.log((1.0*len(image_paths)+1) / (1.0*nbr_occurences + 1)), 'float32')
        test_features = stdSlr.transform(test_features)
        probs = np.array(clf.predict_proba(test_features))
        ind = np.argmax(probs)
        max_prob = np.max(probs)
        if max_prob > best:
            predictions = (classes_names[ind], max_prob)
            best = max_prob
            #print(predictions)
    queue.put(predictions)
Пример #3
0
def f(frame):
    print("entered f %d", frame)
    detections = np.empty((0, 4))
    image = sweep_tensor[frame, :, :]
    image = image / 127
    image = cv2.flip(image, 0)
    image = cv2.flip(image, 1)
    for (x, y, window) in sliding_window(image,
                                         stepSize=10,
                                         windowSize=(winW, winH)):
        print("entered loop 1")
        # if the window does not meet our desired window size, ignore it
        if window.shape[0] != winH or window.shape[1] != winW:
            continue
        window = np.reshape(window, [1, 36, 36, 1])
        # print("window is chosen")
        # lock.acquire()
        # print("Lock acquired")
        y_test_probability = deep_model.predict(window)
        # y_test_probability = 0.5
        # print("work done with lock")
        # lock.release()
        # print("prediction made")
        start_x = x
        end_x = x + winW
        start_y = y
        end_y = y + winH
        if (y_test_probability > 0.90) and (
                np.sqrt(np.square((x + 18) - 100) + np.square((y + 18) - 100))
                > 20):
            detections = np.append(detections,
                                   np.array([(start_x, start_y, end_x, end_y)
                                             ]),
                                   axis=0)
            # cv2.rectangle(clone, (x, y), (x + winW, y + winH), (255, 0, 0), 1)
        # else:
        # 	cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 1)
        # cv2.imshow("Window", clone)
        # cv2.waitKey(1)
        # time.sleep(.0001)
    print("exited loop 1")
    detections = detections.astype(int)
    clone = image.copy()
    # l,_ = detections.shape
    pick = non_max_suppression_fast(detections, 0.3)
    # l,_ = pick.shape
    # print("number of filtered detections",l)
    # for (startX, startY, endX, endY) in pick:
    # 	# print(startY,startX,endX,endY)
    # 	cv2.rectangle(clone, (startX, startY), (endX, endY), (255, 0, 0), 1)
    # for i in range(0,l):

    # 	x = x.astype(int)
    # 	y = y.astype(int)
    # 	cv2.rectangle(clone, (x, y), (x + winW, y + winH), (255, 0, 0), 1)
    # cv2.imshow("Frame:%s"%(1), clone)
    print("Frame:%s" % (frame), "Time taken: %s" % (end - start))
    cv2.waitKey(1)
Пример #4
0
def predictor(im, w, queue):
    global fea_det
    global step_size
    global k
    global voc
    global clf
    global classes_names
    global stdSlr
    global image_paths
    best = 0
    for (x_pt, y_pt, window) in sliding_window(im,
                                               stepSize=16,
                                               windowSize=(w, w)):
        if window.shape[0] != w or window.shape[1] != w:
            continue
        kpts = [
            cv2.KeyPoint(x, y, step_size)
            for y in range(0, window.shape[0], step_size)
            for x in range(0, window.shape[1], step_size)
        ]
        (kpts, des) = fea_det.compute(window,
                                      kpts)  # compute dense descriptors
        des = whiten(des)
        test_features = np.zeros((len(image_paths), k), "float32")
        words, L2distance = vq(des, voc)
        for wd in words:
            test_features[0][wd] += 1
        nbr_occurences = np.sum((test_features > 0) * 1, axis=0)
        idf = np.array(
            np.log((1.0 * len(image_paths) + 1) / (1.0 * nbr_occurences + 1)),
            'float32')
        test_features = stdSlr.transform(test_features)
        probs = np.array(clf.predict_proba(test_features))
        ind = np.argmax(probs)
        max_prob = np.max(probs)
        if max_prob > best:
            predictions = (classes_names[ind], max_prob)
            best = max_prob
            #print(predictions)
    queue.put(predictions)
# 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])
			# print(window.shape)
Пример #6
0
grey = 0
ratio = 0.0
flag = 0
listR = []
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to image")
args = vars(ap.parse_args())

image = cv2.imread(args["image"], cv2.IMREAD_GRAYSCALE)
newHeight = 200
newWidth = int(image.shape[1] * 200 / image.shape[0])
image = cv2.resize(image, (newWidth, newHeight))
clone = image.copy()
(winW, winH) = (80, 80)
for (x, y, window) in sliding_window(image,
                                     stepSize=12,
                                     windowSize=(winW, winH)):
    tempX = x
    tempY = y
    if window.shape[0] != winH or window.shape[1] != winW:
        continue
    for i in range(y, y + winH):  # 300 370
        if (clone[x, i] != 255):  #>255) and (clone[x,i]<200):
            flag = flag + 1
            break
        else:
            continue
    y = tempY
    for i in range(x, x + winW):  # 300 370
        if (clone[x, i] != 255):  #if (clone[i,y]>255) and (clone[i,y]<200):
            flag = flag + 1
Пример #7
0
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)
		time.sleep(0.025)
Пример #8
0
    return '.'.join([i, (d + '0' * n)[:n]])


image = cv2.imread(args["image"])
new_image = image  #cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
(winW, winH) = (smallwindow_size, smallwindow_size)

# I had difficulty getting ffmpeg to crop, so I'll do it here.
# if image.shape != (1580,790):
#   image = image[40:1620,60:850]

heatmap = np.zeros((67, 33, 3))  # np.zeros((154,75,3)) or np.zeros((67,33,3))
count = 0
start = time.time()
for (x, y, window) in sliding_window(new_image,
                                     stepSize=smallwindow_step,
                                     windowSize=(winW, winH)):
    if window.shape[0] != winH or window.shape[1] != winW:
        continue
    window = utils2.skimage.transform.resize(window, (24, 24))
    predictions = classify3.isball(window)
    heatmap[int(x / smallwindow_step),
            int(y / smallwindow_step), 0] = truncate(predictions[0], 3)
    heatmap[int(x / smallwindow_step),
            int(y / smallwindow_step), 1] = truncate(predictions[1], 3)
    count += 1
    #print(predictions)
    # if predictions[1] > smallwindow_threshold:
    #   plt.imshow(window)
    #   plt.show()
### SLIDER SETUP

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())

image = cv2.imread(args["image"])
(winW, winH) = (395, 395)

###

# Cut pool table into 8 images
eight_images = []
count = 0
for (x, y, window) in sliding_window(image,
                                     stepSize=395,
                                     windowSize=(winW, winH)):
    if window.shape[0] != winH or window.shape[1] != winW:
        continue
    eight_images.append(window)
    count += 1

# for i in range(len(eight_images)):
#   plt.imshow(eight_images[i])
#   plt.show()
#   time.sleep(1)

# loads graph
with tf.gfile.FastGFile("logs/trained_graph.pb", 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())