def main(): files = [] temp = [] temp = os.listdir(os.getcwd()) for f in temp: if os.path.isfile(f): f = FileName(f) if f.getFileExt() in '.gmx': files.append(f) #print(f.getName()) for f in files: tree = ET.parse(f.getName()) root = tree.getroot() orig = root.find('origname') strg = orig.text pos = 0 for i in range(1, len(strg)): if strg[-i] == '\\': pos = i break if pos != 0: strg = strg[-pos:] strg = strCheck(strg, f) orig.text = strg tree.write(f.getName())
def detImageFace(self): fileName = askopenfilename() if fileName == '': showerror("Error", "No file selected.\nTry Again") ScrollText.sc.appendStatusText("File Not selected. Try Again") return #face_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml') face_cascade = cv2.CascadeClassifier(self.xmlFileName) img = cv2.imread(fileName) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) count = 1 for (x, y, w, h) in faces: imga = img[y:y + h, x:x + w] name = FileName.getNewFileName("ExtractedFaces", "ExtFace", ".jpg") ScrollText.sc.appendStatusText("Image saved :- %s" % name) count += 1 cv2.imwrite(name, imga) for (x, y, w, h) in faces: img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow('img', img) cv2.waitKey(0) cv2.destroyAllWindows() self.parent.focus_force()
def capVideo(self): global sppp cap = cv2.VideoCapture(0) outputFileName = FileName.getNewFileName("CapturedVideo", "capVid", ".avi") fourcc = cv2.VideoWriter_fourcc(*'MJPG') out = cv2.VideoWriter(outputFileName, fourcc, 20.0, (640, 480)) while (cap.isOpened()): ret, frame = cap.read() if ret == True: frame = cv2.flip(frame, 1) font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = frame.shape cv2.putText(frame, time.strftime("%d/%m/%Y %H:%M:%S "), (w - 350, h - 20), font, .7, (255, 255, 255), 1, cv2.LINE_AA) out.write(frame) cv2.imshow(outputFileName, frame) if cv2.waitKey(sppp) & 0xFF == ord('q'): ScrollText.sc.appendStatusText("Video Saved:-%s" % outputFileName) break else: break cap.release() out.release() cv2.destroyWindow(outputFileName) self.parent.focus_force()
def capImage(self): global sppp camera = cv2.VideoCapture(0) while (camera.isOpened()): ret, image = camera.read() font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = image.shape cv2.putText(image, time.strftime("%d/%m/%Y %H:%M:%S "), (w - 350, h - 20), font, .7, (255, 255, 255), 1, cv2.LINE_AA) cv2.imshow('Image Capture', image) if cv2.waitKey(sppp) & 0xFF == ord('s'): outputFileName = FileName.getNewFileName( "CapturedImage", "capImg", ".jpg") cv2.imwrite(outputFileName, image) #cv2.imshow('image',image) ScrollText.sc.appendStatusText("Image Saved:-%s" % outputFileName) if cv2.waitKey(0) & 0xFF == ord('q'): break break camera.release() cv2.destroyWindow('Image Capture') self.parent.focus_force()
def main(): audioFiles = [] audioDirs = [] temp = [] temp = os.listdir(os.getcwd()) for f in temp: f = FileName(f) if f.getFileExt() == ".gmx": audioDirs.append(f) newDir = os.getcwd() + os.sep + "audio" if os.path.isdir(newDir): audioFiles = os.listdir(newDir) else: print(newDir + " Does not exist program will now die") sys.exit() temp = [] for i in audioDirs: temp.append(i) audioDirs = [] for i in temp: audioDirs.append(SoundFile(i)) for i in audioDirs: i.addTree(ET.parse(i.fileName.getName())) i.orig = i.root.find("origname") i.fileDir = i.orig.text notFound = [] for i in audioDirs: found = False for j in audioFiles: if i.fileDir == j: found = True if not found: notFound.append(i) for i in notFound: print(i.fileName.getName()) print(i.fileDir) print("===")
def saveLog(): sc.statusText.configure(state="normal") logFileName = FileName.getNewFileName("LogFiles", "logFile", ".txt") sc.appendStatusText("Log File Saved :- %s" % logFileName) fo = open(logFileName, "wb") fo.write(sc.statusText.get("1.0", END)) # Close opend file fo.close() sc.statusText.configure(state="disabled")
def liveImageFace(self): global sppp face_cascade = cv2.CascadeClassifier(self.xmlFileName) cap = cv2.VideoCapture(0) while cap.isOpened(): ret, img = cap.read() if ret == True: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) flag = False for (x, y, w, h) in faces: img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) flag = True cv2.imshow('Capture Face', img) if cv2.waitKey(sppp) & 0xFF == ord('s'): if not flag: continue count = 1 for (x, y, w, h) in faces: imga = img[y:y + h, x:x + w] name = FileName.getNewFileName("ExtractedFaces", "ExtFace", ".jpg") ScrollText.sc.appendStatusText("Image saved :- %s" % name) count += 1 font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = imga.shape cv2.putText(imga, time.strftime("%d/%m/%Y"), (w - 80, h - 10), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.putText(imga, time.strftime("%H:%M:%S "), (w - 60, h - 20), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.imwrite(name, imga) cv2.imshow('Capture Face', imga) if cv2.waitKey(0) & 0xFF == ord('q'): break break cv2.destroyWindow('Capture Face') self.parent.focus_force()
def detFaceVideoWebCam(self): global sppp face_cascade = cv2.CascadeClassifier(self.xmlFileName) cap = cv2.VideoCapture(0) outputFileName = FileName.getNewFileName("ExtractVideoHavingFace", "extVid", ".avi") ScrollText.sc.appendStatusText("Extracted Video saved :- %s" % outputFileName) fourcc = cv2.VideoWriter_fourcc(*'MJPG') out = cv2.VideoWriter(outputFileName, fourcc, 20.0, (640, 480)) while cap.isOpened(): ret, img = cap.read() if ret == True: img = cv2.flip(img, 1) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) #count = 1 #for (x,y,w,h) in faces: # imga = img[y:y+h, x:x+w] # name = FileName.getNewFileName("ExtractedFaces", "ExtFace", ".jpg") # ScrollText.sc.appendStatusText("Image saved :- %s"%name) # count+=1 # cv2.imwrite(name, imga) font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = img.shape cv2.putText(img, time.strftime("%d/%m/%Y %H:%M:%S "), (w - 350, h - 20), font, .7, (255, 255, 255), 1, cv2.LINE_AA) flag = False for (x, y, w, h) in faces: flag = True if flag: out.write(img) for (x, y, w, h) in faces: img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow('Extract Faces', img) if cv2.waitKey(sppp) & 0xFF == ord('q'): break cv2.destroyWindow('Extract Faces') self.parent.focus_force()
def capImage(self): global sppp cap = cv2.VideoCapture(0) kernel = np.ones((5,5),np.uint8) while(cap.isOpened()): # Take each frame _, frame = cap.read() frame = cv2.flip(frame, 1) # Convert BGR to HSV hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # define range of blue color in HSV lower = np.array([self.min_H,self.min_S, self.min_V]) upper = np.array([self.max_H,self.max_S,self.max_V]) # Threshold the HSV image to get only blue colors mask = cv2.inRange(hsv, lower, upper) res = cv2.bitwise_and(frame,frame, mask= mask) font = cv2.FONT_HERSHEY_SIMPLEX h,w,z = res.shape cv2.putText(res,time.strftime("%d/%m/%Y %H:%M:%S "),(w - 350,h - 20), font, .7,(255,255,255),1,cv2.LINE_AA) cv2.imshow('frame',frame) #cv2.imshow('mask',mask) cv2.imshow('res',res) if cv2.waitKey(sppp) & 0xFF ==ord('s'): outputFileName = FileName.getNewFileName("colorObjDetected", "colObj", ".jpg") cv2.imwrite(outputFileName,res) #cv2.imshow('image',image) ScrollText.sc.appendStatusText("Image Saved:-%s"%outputFileName) if cv2.waitKey(0) & 0xFF ==ord('q'): break break cv2.destroyAllWindows() cap.release() self.parent.focus_force()
def compFaces(): #value of height and width, size of image for comparision all images of faces are converted into this size the comparision will take place height_width = 150 flag = True def getSsimValude(imageA, imageB): comp_img1 = imageA comp_img2 = imageB comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_BGR2RGB) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_BGR2RGB) pil1 = Image.fromarray(comp_img1) pil2 = Image.fromarray(comp_img2) pil1 = pil1.resize((height_width, height_width), PIL.Image.ANTIALIAS) pil2 = pil2.resize((height_width, height_width), PIL.Image.ANTIALIAS) comp_img1 = cv2.cvtColor(np.array(pil1), cv2.COLOR_RGB2BGR) comp_img2 = cv2.cvtColor(np.array(pil2), cv2.COLOR_RGB2BGR) comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_RGB2GRAY) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_RGB2GRAY) ssimValue = ssim(comp_img1, comp_img2) return ssimValue #creating blank image used for comparision as first image blank_image = np.zeros((height_width, height_width, 3), np.uint8) #laptop resolution width = GetSystemMetrics(0) height = GetSystemMetrics(1) # Create a black image, a window cap = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier( 'C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml' ) #face_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\lbpcascades\HS.xml') count = 1 while cap.isOpened(): ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.5, 5) for (x, y, w, h) in faces: if (flag): prevImage1 = blank_image prevImage2 = blank_image prevImage3 = blank_image prevImage4 = blank_image flag = False y -= 10 x -= 10 h += 20 w += 20 imga = frame[y:y + h, x:x + w] s1 = getSsimValude(prevImage1, imga) s2 = getSsimValude(prevImage2, imga) s3 = getSsimValude(prevImage3, imga) s4 = getSsimValude(prevImage4, imga) if (s1 < 0.55 and s2 < 0.55 and s3 < 0.55 and s4 < 0.55): prevImage4 = imga prevImage3 = prevImage4 prevImage2 = prevImage3 prevImage1 = prevImage2 name = FileName.getNewFileName("EntryFaceRecord", "ERecod", ".jpg") ScrollText.sc.appendStatusText("Image Saved:-%s" % name) count += 1 cv2.imwrite(name, imga) for (x, y, w, h) in faces: y -= 10 x -= 10 h += 20 w += 20 frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow('img', frame) if cv2.waitKey(20) & 0xFF == ord('q'): break cv2.destroyAllWindows()
def detFaceVideoBrowse(self): global speed fileName = askopenfilename() if fileName == '': showerror("Error", "No file selected.\nTry Again") ScrollText.sc.appendStatusText("File Not selected. Try Again") return if not fileName.endswith(".avi"): showerror("Error", "Not valid Format.") ScrollText.sc.appendStatusText("Invalid File Format:-%s" % fileName) return outputFileName = FileName.getNewFileName("ExtractVideoHavingFace", "extVid", ".avi") ScrollText.sc.appendStatusText("Extracted Video saved :- %s" % outputFileName) fourcc = cv2.VideoWriter_fourcc(*'MJPG') out = cv2.VideoWriter(outputFileName, fourcc, 20.0, (640, 480)) face_cascade = cv2.CascadeClassifier(self.xmlFileName) cap = cv2.VideoCapture(fileName) while cap.isOpened(): ret, img = cap.read() if img is None: break if ret == True: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) flag = False for (x, y, w, h) in faces: flag = True if flag: out.write(img) #count = 1 #for (x,y,w,h) in faces: # imga = img[y:y+h, x:x+w] # name = FileName.getNewFileName("ExtractedFaces", "ExtFace", ".jpg") # ScrollText.sc.appendStatusText("Image saved :- %s"%name) # count+=1 # cv2.imwrite(name, imga) for (x, y, w, h) in faces: img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow('img', img) key = cv2.waitKey(speed) if key == ord('q') or key == ord('Q'): cv2.destroyAllWindows() break elif key == ord('f') or key == ord('F'): if speed > 1: speed -= 5 elif key == ord('g') or key == ord('G'): if speed < 1000: speed += 5 cv2.destroyAllWindows() self.parent.focus_force()
def vidAndSendEmail(self): global sppp flag = True sValue = 0.80 def getSsimValude(imageA, imageB, height, width): comp_img1 = imageA comp_img2 = imageB comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_RGB2GRAY) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_RGB2GRAY) ssimValue = ssim(comp_img1, comp_img2) return ssimValue #creating blank image used for comparision as first image #laptop resolution width = GetSystemMetrics(0) height = GetSystemMetrics(1) # Create a black image, a window cap = cv2.VideoCapture(0) height = int(cap.get(4)) width = int(cap.get(3)) blank_image = np.zeros((height, width, 3), np.uint8) count = 1 while cap.isOpened(): ret, frame = cap.read() font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = frame.shape cv2.putText(frame, time.strftime("%d/%m/%Y %H:%M:%S "), (w - 350, h - 20), font, .7, (255, 255, 255), 1, cv2.LINE_AA) if (flag): prevImage1 = blank_image prevImage2 = blank_image prevImage3 = blank_image prevImage4 = blank_image flag = False s1 = getSsimValude(prevImage1, frame, height, width) s2 = getSsimValude(prevImage2, frame, height, width) s3 = getSsimValude(prevImage3, frame, height, width) s4 = getSsimValude(prevImage4, frame, height, width) if (s1 < sValue and s2 < sValue and s3 < sValue and s4 < sValue): prevImage4 = frame prevImage3 = prevImage4 prevImage2 = prevImage3 prevImage1 = prevImage2 #send mail using defferent thread name = FileName.getNewFileName("SurvlImage", "survImage", ".jpg") ScrollText.sc.appendStatusText("Image Saved:-%s" % name) count += 1 cv2.imwrite(name, frame) thread = sendMailThread.sendMailThread(name) thread.start() cv2.imshow('Surveillance System', frame) if cv2.waitKey(sppp) & 0xFF == ord('q'): break cv2.destroyWindow('Surveillance System')
def vidUpAndSendEmail(self): flag = True sValue = 0.80 global speed fileName = askopenfilename() if fileName == '': showerror("Error", "No file selected.\nTry Again") ScrollText.sc.appendStatusText("File Not selected. Try Again") return if not fileName.endswith(".avi"): showerror("Error", "Not valid Format.") ScrollText.sc.appendStatusText("Invalid File Format:-%s" % fileName) return def getSsimValude(imageA, imageB, height, width): comp_img1 = imageA comp_img2 = imageB comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_RGB2GRAY) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_RGB2GRAY) ssimValue = ssim(comp_img1, comp_img2) return ssimValue #creating blank image used for comparision as first image #laptop resolution width = GetSystemMetrics(0) height = GetSystemMetrics(1) # Create a black image, a window cap = cv2.VideoCapture(fileName) height = int(cap.get(4)) width = int(cap.get(3)) blank_image = np.zeros((height, width, 3), np.uint8) count = 1 while cap.isOpened(): ret, frame = cap.read() if (flag): prevImage1 = blank_image prevImage2 = blank_image prevImage3 = blank_image prevImage4 = blank_image flag = False s1 = getSsimValude(prevImage1, frame, height, width) s2 = getSsimValude(prevImage2, frame, height, width) s3 = getSsimValude(prevImage3, frame, height, width) s4 = getSsimValude(prevImage4, frame, height, width) if (s1 < sValue and s2 < sValue and s3 < sValue and s4 < sValue): prevImage4 = frame prevImage3 = prevImage4 prevImage2 = prevImage3 prevImage1 = prevImage2 #send mail using defferent thread name = FileName.getNewFileName("SurvlImage", "survImage", ".jpg") ScrollText.sc.appendStatusText("Image Saved:-%s" % name) count += 1 cv2.imwrite(name, frame) thread = sendMailThread.sendMailThread(name) thread.start() cv2.imshow('Surveillance System', frame) key = cv2.waitKey(speed) if key == ord('q') or key == ord('Q'): cv2.destroyAllWindows() break elif key == ord('f') or key == ord('F'): if speed > 1: speed -= 5 elif key == ord('g') or key == ord('G'): if speed < 1000: speed += 5 cv2.destroyWindow('Surveillance System')
def capVideo(self): global sppp #value of height and width, size of image for comparision all images of faces are converted into this size the comparision will take place height_width = 150 flag = True def getSsimValude(imageA, imageB): comp_img1 = imageA comp_img2 = imageB comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_BGR2RGB) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_BGR2RGB) pil1 = Image.fromarray(comp_img1) pil2 = Image.fromarray(comp_img2) pil1 = pil1.resize((height_width, height_width), PIL.Image.ANTIALIAS) pil2 = pil2.resize((height_width, height_width), PIL.Image.ANTIALIAS) comp_img1 = cv2.cvtColor(np.array(pil1), cv2.COLOR_RGB2BGR) comp_img2 = cv2.cvtColor(np.array(pil2), cv2.COLOR_RGB2BGR) comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_RGB2GRAY) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_RGB2GRAY) ssimValue = ssim(comp_img1, comp_img2) return ssimValue #creating blank image used for comparision as first image blank_image = np.zeros((height_width, height_width, 3), np.uint8) #laptop resolution # Create a black image, a window cap = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier(self.xmlFileName) #face_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\lbpcascades\HS.xml') count = 1 while cap.isOpened(): ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.5, 5) for (x, y, w, h) in faces: if (flag): prevImage1 = blank_image prevImage2 = blank_image prevImage3 = blank_image prevImage4 = blank_image flag = False y -= 10 x -= 10 h += 20 w += 20 imga = frame[y:y + h, x:x + w] s1 = getSsimValude(prevImage1, imga) s2 = getSsimValude(prevImage2, imga) s3 = getSsimValude(prevImage3, imga) s4 = getSsimValude(prevImage4, imga) if (s1 < 0.55 and s2 < 0.55 and s3 < 0.55 and s4 < 0.55): prevImage4 = imga prevImage3 = prevImage4 prevImage2 = prevImage3 prevImage1 = prevImage2 name = FileName.getNewFileName("EntryFaceRecord", "ERecod", ".jpg") ScrollText.sc.appendStatusText("Image Saved:-%s" % name) count += 1 font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = imga.shape imgaa = imga cv2.putText(imgaa, time.strftime("%d/%m/%Y"), (w - 80, h - 10), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.putText(imgaa, time.strftime("%H:%M:%S "), (w - 60, h - 20), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.imwrite(name, imgaa) for (x, y, w, h) in faces: y -= 10 x -= 10 h += 20 w += 20 frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = frame.shape cv2.putText(frame, time.strftime("%d/%m/%Y %H:%M:%S "), (w - 350, h - 20), font, .7, (255, 255, 255), 1, cv2.LINE_AA) cv2.imshow('img', frame) if cv2.waitKey(sppp) & 0xFF == ord('q'): break cv2.destroyAllWindows() self.parent.focus_force()
def openVideo(self): global speed height_width = 150 flag = True def getSsimValude(imageA, imageB): comp_img1 = imageA comp_img2 = imageB comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_BGR2RGB) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_BGR2RGB) pil1 = Image.fromarray(comp_img1) pil2 = Image.fromarray(comp_img2) pil1 = pil1.resize((height_width, height_width), PIL.Image.ANTIALIAS) pil2 = pil2.resize((height_width, height_width), PIL.Image.ANTIALIAS) comp_img1 = cv2.cvtColor(np.array(pil1), cv2.COLOR_RGB2BGR) comp_img2 = cv2.cvtColor(np.array(pil2), cv2.COLOR_RGB2BGR) comp_img1 = cv2.cvtColor(comp_img1, cv2.COLOR_RGB2GRAY) comp_img2 = cv2.cvtColor(comp_img2, cv2.COLOR_RGB2GRAY) ssimValue = ssim(comp_img1, comp_img2) return ssimValue #creating blank image used for comparision as first image blank_image = np.zeros((height_width, height_width, 3), np.uint8) #laptop resolution fileName = askopenfilename() if fileName == '': showerror("Error", "No file selected.\nTry Again") ScrollText.sc.appendStatusText("File Not selected. Try Again") return if not fileName.endswith(".avi"): showerror("Error", "Not valid Format.") ScrollText.sc.appendStatusText("Invalid File Format:-%s" % fileName) return # Create a black image, a window cap = cv2.VideoCapture(fileName) face_cascade = cv2.CascadeClassifier(self.xmlFileName) #face_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\lbpcascades\HS.xml') count = 1 while cap.isOpened(): ret, frame = cap.read() if frame is None: break gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: if (flag): prevImage1 = blank_image prevImage2 = blank_image prevImage3 = blank_image prevImage4 = blank_image flag = False y -= 10 x -= 10 h += 20 w += 20 imga = frame[y:y + h, x:x + w] s1 = getSsimValude(prevImage1, imga) s2 = getSsimValude(prevImage2, imga) s3 = getSsimValude(prevImage3, imga) s4 = getSsimValude(prevImage4, imga) if (s1 < 0.55 and s2 < 0.55 and s3 < 0.55 and s4 < 0.55): prevImage4 = imga prevImage3 = prevImage4 prevImage2 = prevImage3 prevImage1 = prevImage2 name = FileName.getNewFileName("EntryFaceRecord", "ERecod", ".jpg") ScrollText.sc.appendStatusText("Image Saved:-%s" % name) count += 1 font = cv2.FONT_HERSHEY_SIMPLEX h, w, z = imga.shape imgaa = imga cv2.putText(imgaa, time.strftime("%d/%m/%Y"), (w - 80, h - 10), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.putText(imgaa, time.strftime("%H:%M:%S "), (w - 60, h - 20), font, .3, (255, 255, 255), 1, cv2.LINE_AA) cv2.imwrite(name, imgaa) for (x, y, w, h) in faces: y -= 10 x -= 10 h += 20 w += 20 frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow('img', frame) key = cv2.waitKey(speed) if key == ord('q') or key == ord('Q'): cv2.destroyAllWindows() break elif key == ord('f') or key == ord('F'): if speed > 1: speed -= 5 elif key == ord('g') or key == ord('G'): if speed < 1000: speed += 5 cv2.destroyAllWindows() self.parent.focus_force()
def read_files(): # Get the path of initial input files path = "/Users/vivek/PycharmProjects/inverted_index/nz2_merged" index_list, data_list = FileName.getFiles(path) j = 0 link = [] urlsize = [] test1 = "" fileindex = 0 counter = 1 # Create temp file filept = open('temp', 'wb') for i in range(len(index_list)): try: fname = path+"/"+index_list[i] dname = path+"/"+data_list[i] print "Index: "+str(fname) print "Data: "+str(dname) # Unzip input data file and index file with gzip.open(fname, "rb") as f: with gzip.open(dname, "rb") as datapt: for line in f: test1 = line temp = [] temp = line.split() # Read the input data file data = datapt.read(int(temp[3])) # Check if the page is valid or not flag = tokenize.test(data) dictionary = {} # If the page is valid if flag: # Create the dictionary of words of each and every page dictionary = tokenize.parse(data) if len(dictionary) != 0: # Store the URL and size of the page link.append(temp[0]) urlsize.append(temp[3]) for word in dictionary: data = dictionary[word] # Limit the intermediate file upto 250000 number of lines if counter == 250000: filept.close() # Sort the intermediate file using Unix sort os.system("sort -b --output=index"+str(fileindex)+" temp") # Remove temp file os.remove('temp') fileindex += 1 filept = open('temp', 'wb') counter = 0 counter += 1 # Write word, encoded docid and encoded frequency into intermediate file filept.write(word+" ") filept.write(vb_encode(j)) filept.write(" ") filept.write(vb_encode(data)) filept.write("\n") j += 1 except Exception as e: print "Error..." print "Index: "+str(fname) print "Link: "+str(test1) print e pass if counter > 0 and counter < 250000: filept.close() os.system("sort -b --output=index"+str(fileindex)+" temp") os.remove('temp') final = open("Url_Table.txt", 'w') print "Length: "+str(len(link)) # Write into URL table for j in range(len(link)): final.write(str(j) + " " + link[j] + " " + urlsize[j] + "\r") final.close return