Commit 64a584d0 authored by dewmalFernando's avatar dewmalFernando

V1.17

parent 5a2bf325
...@@ -33,12 +33,14 @@ if(result != null){ ...@@ -33,12 +33,14 @@ if(result != null){
<!-- <p>Your account details are below:</p> --> <!-- <p>Your account details are below:</p> -->
<table > <table >
<tr > <tr >
<td>Enhancement type :</td> <td>Contrast Adjustment : Clahe</td>
</tr> </tr>
<tr> <tr>
<td>Method Type :</td> <td>Improve Image Shapness : Unsharp masking</td>
</tr>
<tr>
<td>Noise Type : Gaussian noise</td>
</tr> </tr>
</table> </table>
</div> </div>
</div> </div>
...@@ -247,7 +249,7 @@ function insertVideoAbnormal(newVideo) { ...@@ -247,7 +249,7 @@ function insertVideoAbnormal(newVideo) {
console.log(data) console.log(data)
console.log(data.id) console.log(data.id)
data.path = "E:\\BACKBONE\\videos\\Input.mp4" //data.path = "E:\\BACKBONE\\videos\\Input.mp4"
let id = data.id let id = data.id
fetch(`http://127.0.0.1:5000/startAbnormalBehaviourDetection`, { fetch(`http://127.0.0.1:5000/startAbnormalBehaviourDetection`, {
......
...@@ -10,6 +10,7 @@ from tifffile import askopenfilename ...@@ -10,6 +10,7 @@ from tifffile import askopenfilename
def capture_humans(path): def capture_humans(path):
# path = "E:\\BACKBONE\\videos\\Input.mp4"
print(path) print(path)
protopath = "E:/BACKBONE/abnormal_behavior_detection/Models/Human Detection/MobileNetSSD_deploy.prototxt" protopath = "E:/BACKBONE/abnormal_behavior_detection/Models/Human Detection/MobileNetSSD_deploy.prototxt"
......
This diff is collapsed.
import cv2
import os
from imageEnhancement import ImageSharpening
from imageEnhancement import CreateNewFolderForFrames
def adjustContrast(folder, rate):
contrastAdjustedFrames = CreateNewFolderForFrames.createFolderForContrasted(folder)
path = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folder
count = 10000000
for file in os.listdir(path):
if file.endswith(".jpg"):
# -----Reading the image-----------------------------------------------------
img = cv2.imread(path + "\\" + file)
# -----Converting image to LAB Color model-----------------------------------
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
# -----Splitting the LAB image to different channels-------------------------
l, a, b = cv2.split(lab)
# -----Applying CLAHE to L-channel-------------------------------------------
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(5, 5))
cl = clahe.apply(l)
# -----Merge the CLAHE enhanced L-channel with the a and b channel-----------
limg = cv2.merge((cl, a, b))
# -----Converting image from LAB Color model to RGB model--------------------
final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
cv2.imwrite(contrastAdjustedFrames + "\\%d.jpg" % count, final)
count += 1
value = ImageSharpening.imageSharp(folder, contrastAdjustedFrames, rate)
return value
# Python program to explain os.mkdir() method
# importing os module
import os import os
def createFolder(): def createFolder():
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames" parentPath = "E:\\BACKBONE\\image_enhancement\\Frames"
...@@ -36,9 +34,10 @@ def createFolder(): ...@@ -36,9 +34,10 @@ def createFolder():
print("Directory '% s' created" % directory) print("Directory '% s' created" % directory)
return directory return directory
def createFolderForEnhancedFrames(folderName): def createFolderForEnhancedFrames(folderName):
print("folder name in createFolderForEnhancedFrames : " +folderName) print("folder name in createFolderForEnhancedFrames : " + folderName)
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
totalFiles = 0 totalFiles = 0
totalDir = 0 totalDir = 0
...@@ -58,7 +57,7 @@ def createFolderForEnhancedFrames(folderName): ...@@ -58,7 +57,7 @@ def createFolderForEnhancedFrames(folderName):
directory = "Enhanced_Frames" + str(count) directory = "Enhanced_Frames" + str(count)
# Parent Directory path # Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
# Path # Path
path = os.path.join(parent_dir, directory) path = os.path.join(parent_dir, directory)
...@@ -71,7 +70,142 @@ def createFolderForEnhancedFrames(folderName): ...@@ -71,7 +70,142 @@ def createFolderForEnhancedFrames(folderName):
print("Directory '% s' created" % directory) print("Directory '% s' created" % directory)
return directory return directory
# if __name__ == '__main__':
# # Calling the function
# createFolder()
def createFolderForContrasted(folderName):
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
totalFiles = 0
totalDir = 0
for base, dirs, files in os.walk(parentPath):
print('Searching in : ', base)
for directories in dirs:
totalDir += 1
for Files in files:
totalFiles += 1
print('Total Number of directories', totalDir)
count = totalDir + 1
# Directory
directory = "Contrast_Adjusted_Frames" + str(count)
# Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
# Path
path = os.path.join(parent_dir, directory)
# Create the directory
# 'GeeksForGeeks' in
# '/home / User / Documents'
os.mkdir(path)
print("path : " + path)
print("Directory '% s' created" % directory)
return path
def createFolderForSharpImages(folderName):
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
totalFiles = 0
totalDir = 0
for base, dirs, files in os.walk(parentPath):
print('Searching in : ', base)
for directories in dirs:
totalDir += 1
for Files in files:
totalFiles += 1
print('Total Number of directories', totalDir)
count = totalDir + 1
# Directory
directory = "Sharp_Frames" + str(count)
# Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
# Path
path = os.path.join(parent_dir, directory)
# Create the directory
# 'GeeksForGeeks' in
# '/home / User / Documents'
os.mkdir(path)
print("path : " + path)
print("Directory '% s' created" % directory)
return path
def DenoiseGaussian(folderName):
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
totalFiles = 0
totalDir = 0
for base, dirs, files in os.walk(parentPath):
print('Searching in : ', base)
for directories in dirs:
totalDir += 1
for Files in files:
totalFiles += 1
print('Total Number of directories', totalDir)
count = totalDir + 1
# Directory
directory = "Gaussian_Denoised_Frames" + str(count)
# Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
# Path
path = os.path.join(parent_dir, directory)
# Create the directory
# 'GeeksForGeeks' in
# '/home / User / Documents'
os.mkdir(path)
print("path : " + path)
print("Directory '% s' created" % directory)
return path
def smoothImagesFolder(folderName):
parentPath = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
totalFiles = 0
totalDir = 0
for base, dirs, files in os.walk(parentPath):
print('Searching in : ', base)
for directories in dirs:
totalDir += 1
for Files in files:
totalFiles += 1
print('Total Number of directories', totalDir)
count = totalDir + 1
# Directory
directory = "Smooth_Images" + str(count)
# Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\Frames\\" + folderName
# Path
path = os.path.join(parent_dir, directory)
# Create the directory
# 'GeeksForGeeks' in
# '/home / User / Documents'
os.mkdir(path)
print("path : " + path)
print("Directory '% s' created" % directory)
return path
# Python program to explain os.mkdir() method
# importing os module
import os import os
def createFolder(name):
def createFolderForEnhancedVideos():
parentPath = "E:\\BACKBONE\\image_enhancement\\EnhancedVideos" parentPath = "E:\\BACKBONE\\image_enhancement\\EnhancedVideos"
totalFiles = 0 totalFiles = 0
...@@ -21,22 +19,15 @@ def createFolder(name): ...@@ -21,22 +19,15 @@ def createFolder(name):
count = totalDir + 1 count = totalDir + 1
# Directory # Directory
directory = name directory = "EnhancedVideo" + str(count)
# Parent Directory path
parent_dir = "E:\\BACKBONE\\image_enhancement\\EnhancedVideos\\"
# Path # Path
path = os.path.join(parent_dir, directory) path = os.path.join(parentPath, directory)
# Create the directory # Create the directory
# 'GeeksForGeeks' in # 'GeeksForGeeks' in
# '/home / User / Documents' # '/home / User / Documents'
os.mkdir(path) os.mkdir(path)
print("path : " + path)
print("Directory '% s' created" % directory) print("Directory '% s' created" % directory)
return directory return path
if __name__ == '__main__':
# Calling the function
createFolder()
import cv2 as cv2 import cv2 as cv2
import numpy as np
import os import os
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -20,13 +19,9 @@ def enhanceFrames(folderName, rate): ...@@ -20,13 +19,9 @@ def enhanceFrames(folderName, rate):
for file in os.listdir(path): for file in os.listdir(path):
if file.endswith(".jpg"): if file.endswith(".jpg"):
image = cv2.imread(path + "\\" + file) image = cv2.imread(path + "\\" + file)
# print(image)
# print("file : " + file)
gaussian_3 = cv2.GaussianBlur(image, (0, 0), 3.0) gaussian_3 = cv2.GaussianBlur(image, (0, 0), 3.0)
unsharp_image = cv2.addWeighted(image, 5, gaussian_3, -3.5, 0, image) unsharp_image = cv2.addWeighted(image, 5, gaussian_3, -3.5, 0, image)
cv2.imwrite("E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName+"\\"+enhancedPath+"\\%d.jpg" % count, unsharp_image) cv2.imwrite("E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName+"\\"+enhancedPath+"\\%d.jpg" % count, unsharp_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
count += 1 count += 1
value = FramesToVid.generate_video(folderName, enhancedPath, rate) value = FramesToVid.generate_video(folderName, enhancedPath, rate)
......
...@@ -3,25 +3,19 @@ import os ...@@ -3,25 +3,19 @@ import os
import cv2 import cv2
from PIL import Image from PIL import Image
# Video Generating function # Video Generating function
from imageEnhancement import CreateNewFolderForVideos from imageEnhancement import CreateNewFolderForVideos
def generate_video(folderName, enhancedPath, rate): def generate_video(folderName, parentFolder, rate):
print("folder name : "+folderName) print("Image folder : " + folderName)
print("enhancedPath : "+enhancedPath) print("parentFolder : " + parentFolder)
video_folder_name = "video_"+folderName video_folder_name = "video_" + folderName.split('\\')[5]
CreateNewFolderForVideos.createFolder(video_folder_name)
# Checking the current directory path video_folder_path = CreateNewFolderForVideos.createFolderForEnhancedVideos()
#print(os.getcwd())
# Folder which contains all the images # path = "E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName+"\\"+enhancedPath
# from which video is to be generated path = folderName
#os.chdir("E:\\#ProgrammingWork\\Python\\VideoEnhance\\Frames\\"+folderName)
path = "E:\\BACKBONE\\image_enhancement\\Frames\\"+folderName+"\\"+enhancedPath
mean_height = 0 mean_height = 0
mean_width = 0 mean_width = 0
...@@ -44,9 +38,6 @@ def generate_video(folderName, enhancedPath, rate): ...@@ -44,9 +38,6 @@ def generate_video(folderName, enhancedPath, rate):
mean_width = int(mean_width / num_of_images) mean_width = int(mean_width / num_of_images)
mean_height = int(mean_height / num_of_images) mean_height = int(mean_height / num_of_images)
# print(mean_height)
# print(mean_width)
# Resizing of the images to give # Resizing of the images to give
# them same width and height # them same width and height
for file in os.listdir('.'): for file in os.listdir('.'):
...@@ -65,10 +56,12 @@ def generate_video(folderName, enhancedPath, rate): ...@@ -65,10 +56,12 @@ def generate_video(folderName, enhancedPath, rate):
print(im.filename.split('\\')[-1], " is resized") print(im.filename.split('\\')[-1], " is resized")
# --------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------
image_folder = 'E:\\BACKBONE\\image_enhancement\\Frames\\'+folderName+'\\'+enhancedPath # make sure to use your folder image_folder = folderName
video_name = 'video_'+folderName+'.avi' print("imagefolder ", image_folder)# make sure to use your folder
print("video folder path ", video_folder_path)# make sure to use your folder
video_name = 'Enhanced_Video.avi'
os.chdir("E:\\BACKBONE\\image_enhancement\\EnhancedVideos\\"+video_folder_name) os.chdir(video_folder_path)
images = [img for img in os.listdir(image_folder) images = [img for img in os.listdir(image_folder)
if img.endswith(".jpg") or if img.endswith(".jpg") or
...@@ -85,7 +78,7 @@ def generate_video(folderName, enhancedPath, rate): ...@@ -85,7 +78,7 @@ def generate_video(folderName, enhancedPath, rate):
# the width, height of first image # the width, height of first image
height, width, layers = frame.shape height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, 0, rate, (width, height)) video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*'MP4V'), rate, (width, height))
# Appending the images to the video one by one # Appending the images to the video one by one
for image in images: for image in images:
...@@ -94,5 +87,5 @@ def generate_video(folderName, enhancedPath, rate): ...@@ -94,5 +87,5 @@ def generate_video(folderName, enhancedPath, rate):
# Deallocating memories taken for window creation # Deallocating memories taken for window creation
# cv2.destroyAllWindows() # cv2.destroyAllWindows()
# video.release() # releasing the video generated # video.release() # releasing the video generated
return video_folder_name+"\\"+video_name print(video_folder_path.split('\\')[4])
return video_folder_path.split('\\')[4]
\ No newline at end of file
import cv2
import numpy as np
import os
from imageEnhancement import CreateNewFolderForFrames
from imageEnhancement import RemoveGaussianNoise
def imageSharp(parentFolder, ContrastAdjustedFolder, rate):
SharpImages = CreateNewFolderForFrames.createFolderForSharpImages(parentFolder)
count = 10000000
for file in os.listdir(ContrastAdjustedFolder):
if file.endswith(".jpg"):
image = cv2.imread(ContrastAdjustedFolder + "\\" + file)
kernel_sharpening = np.array([[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1]])
# applying the sharpening kernel to the input image & displaying it.
sharpened = cv2.filter2D(image, -1, kernel_sharpening)
cv2.imwrite(SharpImages + "\\%d.jpg" % count, sharpened)
count += 1
value = RemoveGaussianNoise.removeGaussianNoise(parentFolder, SharpImages, rate)
return value
import cv2
import os
from imageEnhancement import CreateNewFolderForFrames, FramesToVid
from imageEnhancement import Smooth
def removeGaussianNoise(parentFolder, SharpImages, rate):
GaussianDenoised = CreateNewFolderForFrames.DenoiseGaussian(parentFolder)
count = 10000000
for file in os.listdir(SharpImages):
if file.endswith(".jpg"):
img = cv2.imread(SharpImages + "\\" + file)
dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 5)
cv2.imwrite(GaussianDenoised + "\\%d.jpg" % count, dst)
count += 1
# Smooth.imageSmooth(parentFolder, GaussianDenoised)
value = FramesToVid.generate_video(GaussianDenoised, parentFolder, rate)
return value
import cv2
import os
from imageEnhancement import CreateNewFolderForFrames
def imageSmooth(parentFolder, GaussianDenoised):
smooth = CreateNewFolderForFrames.smoothImagesFolder(parentFolder)
count = 10000000
for file in os.listdir(GaussianDenoised):
if file.endswith(".jpg"):
img = cv2.imread(GaussianDenoised + "\\" + file)
blur = cv2.bilateralFilter(img, 60, 90, 90)
cv2.imwrite(smooth + "\\%d.jpg" % count, blur)
count += 1
# if __name__ == '__main__':
# imageSmooth("Frames1", "E:\\BACKBONE\\image_enhancement\\Frames\\Frames1\\Sharp_Frames2")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment