Commit 8d23d0b1 authored by sidharth.singh's avatar sidharth.singh

in-out logic

parent 6c38ec11
This source diff could not be displayed because it is too large. You can view the blob instead.
recognize/0.jpg

2.12 KB | W: | H:

recognize/0.jpg

1000 Bytes | W: | H:

recognize/0.jpg
recognize/0.jpg
recognize/0.jpg
recognize/0.jpg
  • 2-up
  • Swipe
  • Onion skin
recognize/1.jpg

3.24 KB | W: | H:

recognize/1.jpg

3.37 KB | W: | H:

recognize/1.jpg
recognize/1.jpg
recognize/1.jpg
recognize/1.jpg
  • 2-up
  • Swipe
  • Onion skin
...@@ -12,7 +12,9 @@ import os ...@@ -12,7 +12,9 @@ import os
import test import test
import demo import demo
import re import re
frame_count = 1
frame_list = []
in_out = {}
# construct the argument parse and parse the arguments # construct the argument parse and parse the arguments
# ap = argparse.ArgumentParser() # ap = argparse.ArgumentParser()
# ap.add_argument("-i", "--image", default="Trucks/3.jpg", # ap.add_argument("-i", "--image", default="Trucks/3.jpg",
...@@ -138,6 +140,58 @@ def yolo(image, detect_net, refine_net): ...@@ -138,6 +140,58 @@ def yolo(image, detect_net, refine_net):
# show the output image # show the output image
# demo.main(recognize_folder) # demo.main(recognize_folder)
def calculate_time(var):
fields = {
"license_plate": "",
"timestamp" : ""
}
if(len(var)==10):
frame_list.append(var)
if(len(in_out)==0):
print('-------------Adding for first Time----------------')
fields["license_plate"] = var
fields["timestamp"] = datetime.now()
in_out[var] = fields
else:
if var in in_out.keys():
print('-----------If it is present-----------------')
print(var,in_out[var])
print("in_time ",in_out[var]['timestamp'])
print("out_time ",datetime.now())
print('time_interval is ', datetime.now() - in_out[var]['timestamp'])
else:
print('--------------Not present adding----------------')
fields['license_plate'] = var
fields['timestamp'] = datetime.now()
in_out[var] = fields
print(in_out)
# # print(frame_list,in_out)
# # occurances = frame_list.count(var)
# # if(occurances == frame_count):
# if(len(in_out["number_plates"]) == 0):
# fields["license_plate"] = var
# fields["timestamp"] = datetime.now()
# in_out["number_plates"].append(fields)
# else:
# for k in in_out["number_plates"]:
# print('k values are ---------------',k)
# print(var,len(in_out['number_plates']),k['license_plate'])
# if(k['license_plate'] == var):
# print('----------------------------------------------------',val,k['license_plate'])
# flag = False
# else:
# flag = True
# if(flag):
# fields["license_plate"] = var
# fields["timestamp"] = datetime.now()
# in_out["number_plates"].append(fields)
# if(flag == False):
# print('mtach -found------------------- ', k['license_plate'],var)
# print("in-time------------------- ", k["timestamp"])
# print("out-time-------------------", datetime.now())
# print("time interval is ------------------- ", datetime.now()-k["timestamp"])
# in_out['number_plates'] = list(dict.fromkeys(in_out['number_plates']))
# print(in_out)
if __name__ == '__main__': if __name__ == '__main__':
# upload_folder, image_name, image = yolo('Trucks/28.jpg') # upload_folder, image_name, image = yolo('Trucks/28.jpg')
...@@ -150,7 +204,7 @@ if __name__ == '__main__': ...@@ -150,7 +204,7 @@ if __name__ == '__main__':
# print('Text Detected') # print('Text Detected')
# final_list = demo.main(path, length) # final_list = demo.main(path, length)
detect_net, refine_net = test.load_detection() detect_net, refine_net = test.load_detection()
vs = cv2.VideoCapture('videos/demo1.mp4') vs = cv2.VideoCapture('videos/demo.mp4')
writer = None writer = None
time.sleep(1.0) time.sleep(1.0)
count =0 count =0
...@@ -169,7 +223,8 @@ if __name__ == '__main__': ...@@ -169,7 +223,8 @@ if __name__ == '__main__':
print(x1, final_list[0]) print(x1, final_list[0])
if x1: if x1:
print('license-plate is ---> ', final_list[0]) print('license-plate is ---> ', final_list[0])
var = final_list[0] var = final_list[0].replace('.', '').replace(' ', '')
calculate_time(var)
found = True found = True
elif len(final_list) > 1: elif len(final_list) > 1:
for i in range(0, len(final_list) - 1): for i in range(0, len(final_list) - 1):
...@@ -178,7 +233,8 @@ if __name__ == '__main__': ...@@ -178,7 +233,8 @@ if __name__ == '__main__':
print(x1, final_list[i]) print(x1, final_list[i])
if x1: if x1:
print('license-plate is ---> ', final_list[i]) print('license-plate is ---> ', final_list[i])
var = final_list[i] var = final_list[i].replace('.', '').replace(' ', '')
calculate_time(var)
found = True found = True
else: else:
found = False found = False
...@@ -192,7 +248,8 @@ if __name__ == '__main__': ...@@ -192,7 +248,8 @@ if __name__ == '__main__':
if x: if x:
print('license-plate is ---> ', final_list[i] + ' ' + final_list[i + 1]) print('license-plate is ---> ', final_list[i] + ' ' + final_list[i + 1])
var = final_list[i] + ' ' + final_list[i + 1] var = (final_list[i] + ' ' + final_list[i + 1]).replace('.', '').replace(' ', '')
calculate_time(var)
found = True found = True
if found: if found:
...@@ -207,8 +264,8 @@ if __name__ == '__main__': ...@@ -207,8 +264,8 @@ if __name__ == '__main__':
if x: if x:
print('license-plate is ---> ', print('license-plate is ---> ',
final_list[i] + final_list[i + 1] + final_list[i + 2] + final_list[i + 3]) final_list[i] + final_list[i + 1] + final_list[i + 2] + final_list[i + 3])
var = final_list[i] + final_list[i + 1] + final_list[i + 2] + final_list[i + 3] var = (final_list[i] + final_list[i + 1] + final_list[i + 2] + final_list[i + 3]).replace('.', '').replace(' ', '')
calculate_time(var)
found = True found = True
else: else:
found = False found = False
...@@ -223,21 +280,23 @@ if __name__ == '__main__': ...@@ -223,21 +280,23 @@ if __name__ == '__main__':
if x: if x:
print('license-plate is ---> ', print('license-plate is ---> ',
final_list[i] + final_list[i + 1] + final_list[i + 2]) final_list[i] + final_list[i + 1] + final_list[i + 2])
var = (final_list[i] + final_list[i + 1] + final_list[i + 2]) var = (final_list[i] + final_list[i + 1] + final_list[i + 2]).replace('.', '').replace(' ', '')
calculate_time(var)
found = True found = True
else: else:
print('not able to detect') print('not able to detect')
cv2.putText(image, var, (50, 50), cv2.putText(image, var, (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.imshow('image', image) cv2.imshow('image', image)
cv2.waitKey(1) cv2.waitKey(1)
if writer is None: # if writer is None:
# initialize our video writer # # initialize our video writer
fourcc = cv2.VideoWriter_fourcc(*"MJPG") # fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter('output.avi', fourcc, 30, # writer = cv2.VideoWriter('output.avi', fourcc, 30,
(image.shape[1], image.shape[0]), True) # (image.shape[1], image.shape[0]), True)
writer.write(image) # writer.write(image)
fps.update() fps.update()
# if count == 10: # if count == 10:
# break # break
......
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