def loadAllSettings(): # load the standard settings.json allSettings = defaults.LIST_ALL for setting in allSettings: loadSettings(setting) coordList()
def showImage(cropObjs=coordList(), imgPath=getFullPath('source.jpg')): if not os.path.exists(imgPath): print("No Source Image, Fool! Run takeSource!") return else: # load image from path, create a named window image = cv2.imread(imgPath) windowName = "Source Image" cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) # set window size, move window cv2.resizeWindow(windowName, SCREEN_DIMS['width'], SCREEN_DIMS['height']) # cv2.moveWindow(windowName, 0, -50) # add mouse listener function cv2.setMouseCallback(windowName, closeEvent) # add rectangles to the window for obj in cropObjs.myList[1:]: cv2.rectangle(image, obj.topL, obj.botR, (0, 255, 0), 3) cv2.imshow(windowName, image) cv2.waitKey(0)
def cropSource(src_path='source.jpg', debug=False): if not os.path.exists(src_path): print("No Source Image, Fool! Run takeSource!") return else: # load image from path src_img = cv2.imread(util.getFullPath(src_path)) # load the coordList cropObjs = coordList() # iterate through cropped objects, skipping the first(default) object for obj in cropObjs.myList[1:]: name = obj.name + '.jpg' topL = obj.topL botR = obj.botR if debug: print("Cropping Source Image") print(f"\tname: {name}, topL: {topL}, botR: {botR}") print( f"\tx: {topL[0]} -> {botR[0]} // y: {topL[1]} -> {botR[1]}" ) # crop the image: y: bot-> top, x: L->R crop_img = src_img[topL[1]:botR[1], topL[0]:botR[0]] cv2.imwrite(util.getFullPath(name), crop_img)
def cropSetup_add(debug=False): tempList = coordList() if debug: print("adding crop bounding box") image.addCrop(tempList) if debug: print("adding ocrData entry") # use size of coordList to get name of next entry newName = 'crop' + str(len(tempList.myList) - 1) ocrData = settings.loadSettings('OCRData.json') ocr.addEntry_OCRData(ocrData, newName)
def showVid(): with PiCamera() as camera: # camera.resolution = (640, 480) camera.resolution = (800, 480) camera.framerate = 32 # rawCapture = PiRGBArray(camera, size=(640, 480)) rawCapture = PiRGBArray(camera, size=(800, 480)) windowName = "Live Feed" cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) # terminate = False param = [] # set window size, move window cv2.resizeWindow(windowName, SCREEN_DIMS['width'], SCREEN_DIMS['height']) # load in the crop objs cropObjs = coordList() for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): # grab the raw NumPy array representing the image, then initialize the timestamp # and occupied/unoccupied text image = frame.array # draw the rectangles on the image for obj in cropObjs.myList[1:]: cv2.rectangle(image, obj.topL, obj.botR, (0, 255, 0), 3) # show the frame cv2.imshow(windowName, image) cv2.setMouseCallback(windowName, closeEvent, param) cv2.waitKey(1) & 0xFF # clear the stream in preparation for the next frame rawCapture.truncate(0) # if the `q` key was pressed, break from the loop if param: break cv2.destroyWindow(windowName) print("Outside of loop\n\n")
def cropSetup_remove(): ocrData = settings.loadSettings('OCRData.json') if isinstance(ocrData['dataset'], str): dataset = json.loads(ocrData['dataset']) else: dataset = ocrData['dataset'] if len(dataset) >= 1: print("removing last entry from coordList") myList = coordList() myList.popLast() myList.saveSet() print("removing last entry from Settings file") ocr.removeLast_OCRData(ocrData) return True else: print("Noting removed - data is empty") return False
def crop_Source(): print("cropping soruce") myList = coordList() img = 'source.jpg' cropSource(myList, img)
def add_Crop(): print("adding crop") myList = coordList() img = 'source.jpg' addCrop(myList, img)
def show_Img(): print("showing image") myList = coordList() img = 'source.jpg' showImage(myList, img)