1
0

Revert "Implement API key verification system" (#14)

This reverts commit 6188192c7d.
This commit is contained in:
Erick
2022-08-10 00:48:20 +02:00
committed by GitHub
parent 6188192c7d
commit 7485ea995b
+22 -37
View File
@@ -1,11 +1,11 @@
from genericpath import isfile
import io import io
import os import os
import sys import sys
import numpy as np import numpy as np
import cv2 import cv2
import json
from pyautogui import size from pyautogui import size
# Imports the Google Cloud client library
from google.cloud import vision from google.cloud import vision
# Minimum score required for labels detection # Minimum score required for labels detection
@@ -14,42 +14,25 @@ MIN_SCORE_REQUIRED = 0.80
def shape_selection(event, x, y, flags, param): def shape_selection(event, x, y, flags, param):
# grab references to the global variables # grab references to the global variables
global ref_point, crop global ref_point, crop
# if the left mouse button was clicked, record the starting # if the left mouse button was clicked, record the starting
# (x, y) coordinates and indicate that cropping is being performed # (x, y) coordinates and indicate that cropping is being performed
if event == cv2.EVENT_LBUTTONDOWN: if event == cv2.EVENT_LBUTTONDOWN:
ref_point = [(x, y)] ref_point = [(x, y)]
# check to see if the left mouse button was released # check to see if the left mouse button was released
elif event == cv2.EVENT_LBUTTONUP: elif event == cv2.EVENT_LBUTTONUP:
# record the ending (x, y) coordinates and indicate that # record the ending (x, y) coordinates and indicate that
# the cropping operation is finished # the cropping operation is finished
ref_point.append((x, y)) ref_point.append((x, y))
# draw a rectangle around the region of interest # draw a rectangle around the region of interest
cv2.rectangle(image, ref_point[0], ref_point[1], (0, 255, 0), 2) cv2.rectangle(image, ref_point[0], ref_point[1], (0, 255, 0), 2)
cv2.imshow("image", image) cv2.imshow("image", image)
# If a key is present in /keys and has a correct name, add it to enviroment variable key_rel_path= os.path.join('..', 'keys', 'developerKey.json')
key_folder = os.path.join("..", "keys") key = os.path.abspath(key_rel_path)
key_names = ["devKey.json", os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = key
"devkey.json",
"developerkey.json",
"developerKey.json"]
for i in key_names:
success = False
key_rel_path = os.path.join(key_folder, i)
key_abs_path = os.path.abspath(key_rel_path)
if os.path.exists(key_abs_path):
success = True
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = key_abs_path
break
if not success:
print("API keys not found on '~/$YOUR_ENV_NAME/keys'. Closing executable.")
sys.exit(0)
# User input from the command line # User input from the command line
image_name = sys.argv[1] image_name = sys.argv[1]
@@ -64,11 +47,11 @@ if not(os.path.exists(file_name)):
# Press q to exit or enter correct path # Press q to exit or enter correct path
userin = input("Enter the correct path or press q to quit: ") userin = input("Enter the correct path or press q to quit: ")
if userin == "q" or "Q": if userin != "q" or "Q":
sys.exit(0)
else:
file_name = userin file_name = userin
break break
else:
sys.exit(0)
# Initialize the list of reference point # Initialize the list of reference point
ref_point = [] ref_point = []
@@ -97,13 +80,13 @@ clone = image.copy()
cv2.namedWindow("image") cv2.namedWindow("image")
cv2.setMouseCallback("image", shape_selection) cv2.setMouseCallback("image", shape_selection)
# keep looping until the 'q' key is pressed # keep looping until the 'q' key is pressed
while True: while True:
# display the image and wait for a keypress # display the image and wait for a keypress
cv2.imshow("image", image) cv2.imshow("image", image)
key = cv2.waitKey(1) & 0xFF key = cv2.waitKey(1) & 0xFF
# press 'r' to reset the window # press 'r' to reset the window
if key == ord("r"): if key == ord("r"):
image = clone.copy() image = clone.copy()
@@ -111,22 +94,24 @@ while True:
# press 'q' to quit # press 'q' to quit
if key == ord("q"): if key == ord("q"):
sys.exit(0) sys.exit(0)
# if the 'c' key is pressed, break from the loop # if the 'c' key is pressed, break from the loop
elif key == ord("c"): elif key == ord("c"):
break break
if len(ref_point) == 2: if len(ref_point) == 2:
crop_img = clone[ref_point[0][1]:ref_point[1][1], ref_point[0][0]:ref_point[1][0]] crop_img = clone[ref_point[0][1]:ref_point[1][1], ref_point[0][0]:
ref_point[1][0]]
#cv2.imshow("crop_img", crop_img) #uncomment --> show cropped image #cv2.imshow("crop_img", crop_img) #uncomment --> show cropped image
cv2.waitKey(0) #maybe useless cv2.waitKey(0) #maybe useless
cv2.imwrite(os.path.join("..", "images/testset/test0/copy1.jpg"), crop_img) cv2.imwrite('copy1.jpg', crop_img)
# close all open windows # close all open windows
cv2.destroyAllWindows() cv2.destroyAllWindows()
# File used for label detection # File used for label detection
target_file = os.path.abspath(os.path.join("..", "images/testset/test0/copy1.jpg")) target_file = os.path.abspath('copy1.jpg')
# Loads the image into memory # Loads the image into memory
with io.open(target_file, 'rb') as image_file: with io.open(target_file, 'rb') as image_file:
content = image_file.read() content = image_file.read()