-
Notifications
You must be signed in to change notification settings - Fork 2
Archive Image
In CAM2ImageArchiver.py, there is a function named archive() and it is what user need to download images. The function takes in a list of camera objects, duration of entire parsing process, time interval to parse image, result path and a flag to remove result folder if parsing fail. For example, user has a list of camera objects that they want to parse image from.
camObj1 = {'camera_type': 'ip', 'is_active_image': True}
camObj2 = {...}
camObj3 = {...}
camList = [camObj1, camObj2, camObj3]
archiver = CAM2ImageArchiver(num_processes=1, result_path='results/', image_difference_percentage=90)
archiver.archive(camObjects=camList, duration=1, interval=1, result_path=None, remove_after_failure=True)
Above will generate a list of image folders if parse successfully.
What might went wrong if parse fail?
Wrong URL, Website down, Camera get migrated to other place
-
Transform each dictionary inside of camera list into Camera Instances. There are three main type of camera class such as IPCamera, NonIPCamera and StreamCamera. First step is to turn each camera dictionary into their camera class accordingly.
-
Then we create result directories to store images from each camera.
-
Start multithreading on downloading images => Camera Handler
-
Remove directory if downloading failed for that specific camera
In run(), each camera object will call a method named 'get_frame()' to download image. Each camera class has their own way of downloading. IP and NonIP camera use ImageParser which essentially read content from HTTP response. Stream camera use cv2.VideoCapture() to download frame. Detailed implementation can be viewed in StreamParser.py.
If parsing failed, that specific camera object will be saved into a list which will be used to remove from cameraList assuming the 'remove_after_failure' flag is true. Otherwise, we will save the successfully parsed image. Before we save the image, we will create subdirectory indicating each camera objects. Remember we passed in a camera list and we created a parent folder to contain all these camera objects earlier. Now we need to create subdirectories for each camera objects. Then we do a pixel-by-pixel value check on current frame with last frame to avoid saving duplicate images. User will decide a percentage value to indicate the threshold for differentiating duplicate image.