Commit 613aba74 authored by IT18052152_Perera H.G.G.M's avatar IT18052152_Perera H.G.G.M

Merge branch 'IT18052152_Givindu' into 'master'

V1.16.2

See merge request !91
parents 5228f988 99a82bb9
......@@ -20,14 +20,12 @@ def capture_humans(path):
# detector.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
# detector.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
"bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant", "sheep",
"sofa", "train", "tvmonitor"]
CLASSES = []
classFile = 'E:/BACKBONE/abnormal_behavior_detection/Models/Human Detection/class.names'
with open(classFile, 'rt') as f:
CLASSES = f.read().rstrip('\n').split('\n')
print("STEP 1 ON PROGRESS...")
print("test12345")
print("test11")
#Get input video
......@@ -50,7 +48,7 @@ def capture_humans(path):
while True:
ret, frame = cap.read()
if ret != False:
frame = imutils.resize(frame, width=500)
frame = imutils.resize(frame, width=800)
total_frames = total_frames + 1
(H, W) = frame.shape[:2]
......
......@@ -36,7 +36,7 @@ def weaponDetection():
## Model Files
modelConfiguration = "E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom.cfg"
modelWeights = "E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom_last.weights"
modelWeights = "E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom_best.weights"
net = cv.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
......@@ -70,32 +70,8 @@ def weaponDetection():
box = bbox[i]
x, y, w, h = box[0], box[1], box[2], box[3]
# Detect handguns
if classIds[i] == 0:
# print(x,y,w,h)
text = "{:.4f}%".format((confs[i]) * 100)
print("Suspect Detected : ", "[", text, "]")
cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
(x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
# save detected frames
cv2.imwrite('C:/Users/Givindu/Desktop/New folder/frames/Suspects with Weapons/frame%d.jpg' % count, img)
count += 1
# Create and save in a CSV file
type = "Abnormal Activity"
weapon = "The Pistol was used as a weapon"
with open('C:/Users/Givindu/Desktop/New folder/frames/Abnormal Activity.csv', 'w', newline='') as file:
Num += 1
TimeD = start - time.time()
arr = [Num, type, weapon, TimeD]
writer = csv.writer(file)
writer.writerow(field)
writer.writerow(arr)
# Detect Knives
if classIds[i] == 1:
# print(x,y,w,h)
text = "{:.4f}%".format((confs[i])*100)
......@@ -120,6 +96,8 @@ def weaponDetection():
writer.writerow(arr)
while True:
success, img = cap.read()
if success != False:
......
......@@ -36,7 +36,7 @@ def weaponDetection():
## Model Files
modelConfiguration = "E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom.cfg"
modelWeights = "E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom_last.weights"
modelWeights = "E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom_best.weights"
net = cv.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
......@@ -70,8 +70,34 @@ def weaponDetection():
box = bbox[i]
x, y, w, h = box[0], box[1], box[2], box[3]
# Detect handguns
if classIds[i] == 0:
if classIds[i] == '0':
# print(x,y,w,h)
text = "{:.4f}%".format((confs[i])*100)
print("Suspect Detected : ", "[", text, "]")
# cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
# cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
cv2.imwrite('E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame%d.jpg' % count, img)
count += 1
# Create and save in a CSV File
type = "Abnormal Activity"
weapon = "The Pistol was used as a weapon"
with open('E:/BACKBONE/abnormal_behavior_detection/CSV/Abnormal Activity.csv', 'w', newline='') as file:
Num += 1
TimeD = time.time() - start
arr = [Num, type, weapon, TimeD]
writer = csv.writer(file)
writer.writerow(field)
writer.writerow(arr)
# Detect knives
if classIds[i] == 1:
# print(x,y,w,h)
text = "{:.4f}%".format((confs[i])*100)
print("Suspect Detected : ", "[", text, "]")
......@@ -79,6 +105,7 @@ def weaponDetection():
#cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
# save detected frames
cv2.imwrite('E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame%d.jpg' % count, img)
count += 1
......@@ -94,6 +121,33 @@ def weaponDetection():
writer.writerow(arr)
# Detect grenades
if classIds[i] == '2':
# print(x,y,w,h)
text = "{:.4f}%".format((confs[i])*100)
print("Suspect Detected : ", "[", text, "]")
#cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
#cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
# save detected frames
cv2.imwrite('E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame%d.jpg' % count, img)
count += 1
# Create and save in a CSV File
type = "Abnormal Activity"
weapon = "The Grenade was used as a weapon"
with open('E:/BACKBONE/abnormal_behavior_detection/CSV/Abnormal Activity.csv', 'w', newline='') as file:
Num += 1
TimeD = time.time() - start
arr = [Num, type, weapon, TimeD]
writer = csv.writer(file)
writer.writerow(field)
writer.writerow(arr)
while True:
success, img = cap.read()
if success != False:
......
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