def ModelLoader(loc='models/9G_tanh_model_105906112019.h5'): print("\t\t\n #### Running ModelLoader Function ####\n") try: print("Importing Packages Required...",end="##") from tensorflow.keras.models import load_model #from tensorflow.keras.models import model_from_json print("...Import Sucessful") except Exception as exp: print("\n\t##Error in IMPORT...Check if all packages are properly Installed##\n\tError:\n\t\t",exp) print("Importing Trained Model using \"h5\" File...##",end=" ") try: loc='models/9G_tanh_model_105906112019.h5' model=load_model(loc) gv.update('modelUsed',loc) except FileNotFoundError: ftypes = [('Hierarchical Data Format(HDF)',"*.h5")] tt1 = "Hierarchical Data Format (HDFv5) Picker" filename1=custom_utilities.FileFolderPicker(ftypes,tt1) model=load_model(filename1) gv.update(filename1) except Exception as ex: print("!! Error !! : \n\t",ex) print("======== Model Loaded from Disk. ========") return model
def saveNewAction(gesture, newAction): print("\nAction : Change Action Assigned To Gesture-", gesture, ' TO ::', newAction) gesture = gesture[1:] gv.update(str(gesture), str(newAction), 'information') #print(gv.get_global_values('','information')[2]) print("Main.py : Updated New Action for Gesture-", gesture, " :: ", newAction, '\n')
def uiControlMode(permission): print("\nHome : Toggle uiControlMode.") if permission == 'ON': gv.update('uiControlMode', 'True', 'global') elif permission == 'OFF': gv.update('uiControlMode', 'False', 'global') print("Main.py : UI Control Mode Toggled :: ", permission, '\n') return True
def newGestureName(a): print("\nGesture : Passed New Gesture Name is : ", a) global infoDict, bufferData bufferData = infoDict bufferData[a] = 'None' gv.update('gestures', bufferData, 'buffer') print( "Main.py : Added New Gesture Name to BufferInformation Zone.\n\tProceed With Adding New Gesture.\n" ) return True
def finalizeModel(): print("\nGesture : Finalize the New Neural Network for use.") import shutil import time current_time = time.strftime("%I-%M-%b%e-%Y") modelName = "models/newModel @" + current_time + ".h5" shutil.move("../generatedData/newModel.h5", modelName) gv.update('modelToBeUsed', modelName, 'global') print("Main.py : New Model Finalized to be used in Next Camera ReStart.\n") return True
def blob_tracker(c, frame, frame_full): global i ((x, y), radius) = minEnclosingCircle(c) M = moments(c) center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])) if i == 50: for z in range(1, 33): pts.append(center) i += 1 #print(center) if radius > 10: circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2) circle(frame, center, 5, (0, 0, 255), -1) pts.appendleft(center) #print('The point is ',pts) for index in np.arange(1, len(pts)): #print("here") # if either of the tracked points are None, ignore # them if pts[index - 1] is None or pts[index] is None: continue if index == 1 and pts[-10] is not None: # compute the difference between the x and y # coordinates and re-initialize the direction # text variables dX = pts[-10][0] - pts[index][0] dY = pts[-10][1] - pts[index][1] (dirX, dirY) = ("", "") # ensure there is significant movement in the # x-direction if np.abs(dX) > 20: dirX = "East" if np.sign(dX) == 1 else "West" # ensure there is significant movement in the # y-direction if np.abs(dY) > 20: dirY = "North" if np.sign(dY) == 1 else "South" # handle when both directions are non-empty if dirX != "" and dirY != "": direction = "{}-{}".format(dirY, dirX) # otherwise, only one direction is non-empty else: direction = dirX if dirX != "" else dirY #print(dirX,dirY) thickness = int(np.sqrt(32 / float(index + 2)) * 1.5) line(frame_full, pts[index - 1], pts[index], (250, 0, 25), thickness) #print(dX,dY) #gv.update('direction',direction,'global') putText(frame_full, direction, (500, frame.shape[0] + 85), FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) putText(frame_full, "dx: {}, dy: {}".format(dX, dY), (380, frame.shape[0] + 85), FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1) gv.update('dX', dX, 'global') gv.update('dY', dY, 'global') return frame
def changeModelToBeUsed(newModel): print("\nModels : Change Model to be Used to :: ", newModel) newModel = 'models/' + str(newModel) gv.update('modelToBeUsed', newModel, 'global') print("Main.py : Changed Model to be Used to :: %s.\n" % newModel)