Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import pyodbc
  2. from neuro import Neuro
  3. from frame import Frame
  4.  
  5. server = '10.0.0.43'
  6. database = 'mb'
  7. username = 'usrMB'
  8. password = 'asdqaz'
  9.  
  10.  
  11. class Processing(object):
  12. def __init__(self, save_path, sqr_percent, classes):
  13. self.conn = pyodbc.connect('DSN=MSSQL;UID=usrMB;PWD=asdqaz')
  14. self.get_tasks = 'SELECT ID_task_for_analisis, ID_Request ' \
  15. 'FROM TasksForAnalisis WHERE id_type_processing = 1 AND Date_completed IS NULL'
  16. self.get_photo_video = 'SELECT is_photo, Link_Download, time_st, Time_fin, ID_Video FROM PhotoVideoRequests ' \
  17. 'WHERE ID_request = %s'
  18. self.update_detected_items = 'INSERT INTO DetectedItems(ID_Video, ID_task_for_analisis, ID_Type_item, ' \
  19. 'X_top_right, Y_top_right, X_bottom_left, Y_bottom_left, Date_add) ' \
  20. 'VALUES (%s,%s,%s,%s,%s,%s,%s,%s)'
  21. self.update_event_alarm = ''
  22. self.update_task_for_analisis_date_completed = 'UPDATE TasksForAnalisis SET ' \
  23. 'Date_comleted = CONVERT(time, SYSDATETIME())' \
  24. ' WHERE ID_task_for_analisis = %s'
  25.  
  26.  
  27. def process(self):
  28. cursor = self.conn.cursor()
  29. cursor.execute(self.get_tasks)
  30. results = cursor.fetchall()
  31. for result in results:
  32. print("TasksForAnalisis field:", result)
  33. task_id, request_id = result[0], result[1]
  34. # get photo_video
  35. cursor.execute(self.get_photo_video % request_id)
  36. photo_videos = cursor.fetchall()
  37. for photo_video in photo_videos:
  38. is_photo, link_for_download, time_start, time_end, video_id = photo_video[0], photo_video[1], \
  39. photo_video[2], photo_video[3], \
  40. photo_video[4]
  41. # download file by link... #image_path, save_path, interest_zones=None, yolo_thresh=0.13, sqr_percent=40
  42. images, frames = Frame.image_treatment(image_path, self.save_path, interest_zones, yolo_thresh,
  43. self.sqr_percent)
  44. print("images:", images)
  45. print('frames:', frames)
  46. alarm = 0
  47. for i in range(len(images)):
  48. p = self.neuro_network.predict(images[i])
  49. print('predict:', p, self.neuro_network.get_real_class_name_by_number(p))
  50. if self.neuro_network.is_alarm_class(p):
  51. alarm = 1
  52. if self.neuro_network.get_real_class_name_by_number(p) in self.classes:
  53. continue
  54. type_object_id = self.neuro_network.our_class_db_mapper(p)
  55. insert = self.update_detected_items % (video_id, task_id, type_object_id, frames[i][0],
  56. frames[i][1], frames[i][2], frames[i][3])
  57. cursor.execute(insert)
  58. self.conn.commit()
  59. cursor.execute(self.update_task_for_analisis_date_completed % task_id)
  60. self.conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement