Skip to content

Commit

Permalink
First Init
Browse files Browse the repository at this point in the history
  • Loading branch information
coxifred committed Mar 1, 2022
1 parent 40d6b94 commit 745a2fc
Show file tree
Hide file tree
Showing 41 changed files with 93,419 additions and 0 deletions.
Binary file added images_resources4wiki/PimpMyPhototheque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images_resources4wiki/PimpMyPhototheque1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python -m venv venv
venv\scripts\pip install imutils numpy opencv-python flask netifaces requests flask_apscheduler flask_caching apscheduler jsons
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python -m venv venv
./venv/bin/pip install imutils numpy opencv-python flask netifaces requests flask_apscheduler flask_caching apscheduler jsons
96 changes: 96 additions & 0 deletions thread/detectBlur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# import the necessary packages
from imutils import paths
from utils.functions import Functions
from utils.singleton import Singleton
from datetime import datetime
import time
import cv2
import os


class detectBlur:


def variance_of_laplacian(self,image):
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(image, cv2.CV_64F).var()

def prepare(self,imagePath,threshold):
self.imagePath=imagePath
self.threshold=threshold
self.id=Functions.getDateFormat("default") + "_" + self.imagePath.replace("/","_").replace("\\","_").replace(":","_")
self.progression=0
self.step="Init"
self.resultBlurredFile=""
self.resultNotBlurredFile=""
self.blurredCount=0
self.notBlurredCount=0
self.blurredSize=0
self.startTime=datetime.now()
self.total=0
self.elapsedTime=0
self.stop=False
self.aborted=False
singleton=Singleton()
singleton.analysis.append(self)

def run(self):
singleton=Singleton()
resultPath=singleton.parameters["resultPath"].replace("\\","/")
Functions.log("DBG","Results will be stored into " + resultPath,"site")
self.resultBlurredFile=resultPath + "/" + self.id + ".blurred"
self.resultNotBlurredFile=resultPath + "/" + self.id + ".notblurred"
blurredFile = open( self.resultBlurredFile, "w")
notBlurredFile = open(self.resultNotBlurredFile, "w")
# loop over the input images
self.total=0
self.step="Counting pictures"

for imagePathing in paths.list_images(self.imagePath):
self.total+=1
i=0
self.step="Working.."
Functions.log("DBG","Starting Analysis on " + self.imagePath + " with threshold = " + str(self.threshold) + "%","site")
for imagePathing in paths.list_images(self.imagePath):
if self.stop:
self.step="Aborting.."
Functions.log("DBG"," --> Aborting analysis " + imagePathing,"detectBlur")
blurredFile.close()
notBlurredFile.close()
time.sleep(5.0)
self.step="Aborted"
time.sleep(5.0)
self.aborted=True
return
Functions.log("DBG"," --> Analysing " + imagePathing,"detectBlur")
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePathing)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = self.variance_of_laplacian(gray)
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < self.threshold:
Functions.log("DBG",imagePathing + " is blurry at " + str(fm) + "% threshold was " + str(self.threshold),"detectBlur")
size=os.path.getsize(imagePathing)
blurredFile.write("1;" + imagePathing + ";" + str(fm) + ";" + str(self.threshold) + ";" + str(size) + "\n");
self.blurredSize+=size
self.blurredCount+=1
else:
Functions.log("DBG",imagePathing + " not blurry " + str(fm) + "% threshold was " + str(self.threshold),"detectBlur")
notBlurredFile.write("0;" + imagePathing + ";" + str(fm) + ";" + str(self.threshold) +"\n");
self.notBlurredCount+=1
if i%10 == 0:
blurredFile.flush()
notBlurredFile.flush()
i+=1
self.progression=i * 100 / self.total;
self.elapsedTime=datetime.now() - self.startTime
Functions.log("DBG","Writing Blurred results inside " + str(blurredFile),"detectBlur")
Functions.log("DBG","Writing Not Blurred results inside " + str(notBlurredFile),"detectBlur")
blurredFile.close()
notBlurredFile.close()
self.step="Finished"
Functions.log("DBG","Ending Analysis on " + self.imagePath + " with threshold = " + str(self.threshold) + "%","site")
Empty file added utils/__init__.py
Empty file.
256 changes: 256 additions & 0 deletions utils/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
import re
import datetime
import subprocess
import sys
import threading
import hashlib
import requests
import warnings
import importlib
import json
import os
from utils.singleton import Singleton
from utils.timeout import TimeoutFunction



class Functions:

@staticmethod
def log(level, message, source):
date = str(datetime.datetime.now())
singleton=Singleton()
aLog=date + " " + "[" + threading.current_thread().name + "] " + level + " " + source + " " + message
if ( level == "DBG" ):
if singleton.debug:
Functions.logdebug()
print(aLog, flush=True)
elif ( level == "ERR" or level == "WNG" or level == "DEAD" ):
Functions.logred()
print(aLog,end='', flush=True)
Functions.lognormal()
elif ( level == "ASK" ):
Functions.logyellow()
print(aLog, flush=True)
else:
Functions.lognormal()
print(aLog, flush=True)
if ( level == "DEAD" ):
sys.exit(1)
singleton.logs.append(aLog)
f= open("pimpMyPhototheque.log","a+")
f.write(aLog + "\r\n")
sys.stdout.flush()

@staticmethod
def command(aCommand,aParameter):
Functions.log("DBG","Running a command " + aCommand + " with parameter " + aParameter,"CORE")
importlib.import_module('communication')
Functions.log("DBG","Trying instanciation of " + aCommand,"CORE")
mod=importlib.import_module('.' + aCommand,package="communication")
aRealCommand = getattr(mod, aCommand)
return aRealCommand().send()


@staticmethod
def timeoutF(function,timeout):
try:
Functions.log("DBG","Running a timeout function " + str(function) + " with " + str(timeout) + " timeout second(s)","CORE")
TimeoutFunction(function, timeout)
except TimeoutFunctionException:
Functions.log("WNG","Too slow, function is running over " + str(timeout) + " sec(s)","CORE")

@staticmethod
def logred():
sys.stdout.write("\033[1;37;41m")
sys.stdout.flush()

@staticmethod
def logyellow():
sys.stdout.write("\033[1;33;40m")
sys.stdout.flush()

@staticmethod
def lognormal():
sys.stdout.write("\033[1;37;40m")
sys.stdout.flush()

@staticmethod
def logdebug():
sys.stdout.write("\033[1;36;40m")
sys.stdout.flush()

@staticmethod
def requestHttp(request):
Functions.log("DBG","HttpRequest: " + request,"Functions")
requests.packages.urllib3.disable_warnings()
r = requests.get(request, verify=False)
Functions.log("DBG","Response code: " + str(r.status_code),"Functions")
if r.status_code == 200:
body = r.content.decode()
Functions.log("DBG","Response : " + str(body),"Functions")
array=body.split("\n")
while '' in array:
array.pop(array.index(''))
return array
else:
Functions.log("ERR","Error while request " + str(r.text),"Functions")
raise Exception('Error while request')

@staticmethod
def getFieldFromString(string,delimiter,fieldNumber):
try:
return re.split(delimiter,string)[fieldNumber]
except Exception as err:
Functions.log("WNG","Error while trying to use getFieldFromString on " + string + ", perhaps no separator " + delimiter + ", default behavior is to return the full string, error was "+ str(err),"Functions.getFieldFromString")
return string

@staticmethod
def getFromFieldFromString(string,delimiter,fieldNumber):
tab=re.split(delimiter,string);
return tab[fieldNumber:]

@staticmethod
def getFirstMatchInAFile(string,file):
with open(file, "r") as f:
for line in f.readlines():
if string in line:
f.close()
return(line.rstrip('\n'))

@staticmethod
def getFirstMatchInArray(string,array):
for line in array:
if string in line:
return(line.rstrip('\n'))
@staticmethod
def getLastMatchInArray(string,array):
returnLine=""
for line in array:
if string in line:
returnLine=line
return returnLine

@staticmethod
def getFirstMatchReInArray(regexp,array):
returnLine=""
for line in array:
#Functions.log("DBG","Looking for " + regexp + " in line " + line,"Functions")
if re.match(regexp, line) is not None:
#Functions.log("DBG","Match for " + regexp + " in line " + line,"Functions")
return line

@staticmethod
def getLastMatchReInArray(regexp,array):
returnLine=""
for line in array:
#Functions.log("DBG","Looking for " + regexp + " in line " + line,"Functions")
if re.match(regexp, line) is not None:
#Functions.log("DBG","Match for " + regexp + " in line " + line,"Functions")
returnLine=line
return returnLine

@staticmethod
def getFirstMatchInLine(string,line):
array=line.split("\n")
return Functions.getFirstMatchInArray(string,array).rstrip('\n')

@staticmethod
def displayFromLastSeenPatternFromArray(string,array):
returnArray=[]
for line in array:
if string in line:
del returnArray[:]
returnArray.append(line)
else:
returnArray.append(line)
return returnArray

@staticmethod
def getLastMatchInLine(string,line):
array=line.split("\n")
return Functions.getLastMatchInArray(string,array).rstrip('\n')

@staticmethod
def kommandShell(aKommand):
return_output=subprocess.check_output(aKommand,shell=True).decode('utf-8').rstrip('\n')
return return_output

@staticmethod
def kommandShellInArray(aKommand):
return_output=Functions.kommandShell(aKommand).split('\n')
return return_output

@staticmethod
def getDateFormat(format):
if format == "default":
format='%Y%m%d%H%M%S'
return datetime.datetime.now().strftime(format)

@staticmethod
def getDateFormatFromDate(date,format):
if format == "default":
format='%Y%m%d%H%M%S'
return date.strftime(format)

@staticmethod
def getDateFormatFromString(stringDate,format):
if format == "default":
format='%Y%m%d%H%M%S'
return datetime.datetime.strptime(stringDate,format)

@staticmethod
def loadFileInALine(file):
lines=""
with open(file, "r") as f:
for line in f.readlines():
lines += line +"\n"
f.close()
return(lines.rstrip('\n+'))

@staticmethod
def writeArrayInAFile(file,array):
Functions.log("DBG","Writing " + str(len(array)) + " line(s) in " + file,"Functions")
aFile = open(file, "w")
for line in array:
aFile.write(line + "\n");

@staticmethod
def writeArrayInAFileAppend(file,array):
Functions.log("DBG","Writing " + str(len(array)) + " line(s) in " + file,"Functions")
aFile = open(file, "a+")
for line in array:
aFile.write(line + "\n");

@staticmethod
def loadFileInArrayWithRange(file,fromRange,toRange):
lines=[]
with open(file, "r") as f:
i=0
for line in f.readlines():
if ( i >= fromRange and i <= toRange ):
lines.append(line.rstrip('\n+'))
i+=1
f.close()
return(lines)

@staticmethod
def loadFileInArray(file):
lines=[]
with open(file, "r") as f:
for line in f.readlines():
lines.append(line.rstrip('\n+'))
f.close()
return(lines)

@staticmethod
def removeLineFromFile(file,aLine):
aFile = open(file + '.new', "w")
with open(file, "r") as f:
for line in f.readlines():
if aLine not in line:
aFile.write(line);
f.close()
aFile.close()
os.remove(file)
os.rename(file + '.new', file)
Loading

0 comments on commit 745a2fc

Please sign in to comment.