From 0af41f42870a194bc17bcfecc50a56bc39f70b2b Mon Sep 17 00:00:00 2001 From: intrigus Date: Tue, 23 Nov 2021 16:44:32 +0100 Subject: [PATCH 1/4] Require Python 3.9, add dependency install command --- readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index f874fa0..d056952 100644 --- a/readme.md +++ b/readme.md @@ -5,11 +5,15 @@ ci2v searches videos for frames most similar to an image. ## Requirements -* python +* python 3.9 (might work with lower versions, but is untested!) * numpy * opencv * scikit-image +```bash +pip install scikit-image opencv-python numpy +``` + ## How to use it @@ -83,4 +87,4 @@ Search recursively through the specified directory for video files and process e ci2v is built around **OpenCV** and **scikit-image**, and uses the latter's [*Structural similarity index*](http://scikit-image.org/docs/dev/auto_examples/plot_ssim.html) function to compare an input image to a video frame. -Because `ssim` can be slow with large images, ci2v rescales images to 10x10px greyscale arrays. This means ci2v can search a video at around 200fps and still find acceptable matches. \ No newline at end of file +Because `ssim` can be slow with large images, ci2v rescales images to 10x10px greyscale arrays. This means ci2v can search a video at around 200fps and still find acceptable matches. From 53d9eeb25c48dff1daff5b40cd7c5cc5a106a72a Mon Sep 17 00:00:00 2001 From: intrigus Date: Tue, 23 Nov 2021 16:46:22 +0100 Subject: [PATCH 2/4] Update printing for python 3. --- ci2v.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ci2v.py b/ci2v.py index e0c495c..44af96b 100644 --- a/ci2v.py +++ b/ci2v.py @@ -99,13 +99,13 @@ def parse_video(image, video, n_matches, break_point=False, verbose=False): def sort_results(results, output=False): #sort results - print '\n' + print('\n') sorted_results = sorted(results, key=operator.itemgetter('similarity'), reverse=True) n = 0 - print '\n--results:' + print('\n--results:') for res in sorted_results: n += 1 - print '#%s\t%s\t%s\t: %s' % (n, res['filename'], res['frame'], res['similarity']) + print('#%s\t%s\t%s\t: %s' % (n, res['filename'], res['frame'], res['similarity'])) #save matched frames if output: @@ -126,7 +126,7 @@ def walk(source_image, directory, number=1, break_point=False): for ext in extentions: if file.endswith(ext): video_fn = (os.path.join(root, file)) - print video_fn + print(video_fn) similarities = parse_video(source_image, video_fn, n_matches=number, @@ -181,24 +181,24 @@ def main(): #either walk directory or hande single file if args.directory: #scan directory and process each video file - print '\n--reading videos:' + print('\n--reading videos:') results = walk(source_image, args.directory, args.number, args.break_point) s_results = sort_results(results, args.output) else: #process single video file - print '\n--reading video:' + print('\n--reading video:') similarities = parse_video(source_image, args.video, n_matches=args.number, break_point=args.break_point) - print '\n\n--results:' + print('\n\n--results:') #results to cli n = 0 for d in similarities: n += 1 - print '#%s\t%s\t: %s' % (n, d['frame'], d['similarity']) + print('#%s\t%s\t: %s' % (n, d['frame'], d['similarity'])) #save matched frames if args.output: @@ -206,7 +206,7 @@ def main(): seconds_taken = time.clock() - start time_taken = str(datetime.timedelta(seconds=seconds_taken)) - print '\n--time taken: \n%s\n' % time_taken + print('\n--time taken: \n%s\n' % time_taken) if __name__ == '__main__': From 3b8abf7d3c81372526f891cf8b790549b5f62275 Mon Sep 17 00:00:00 2001 From: intrigus Date: Tue, 23 Nov 2021 16:46:45 +0100 Subject: [PATCH 3/4] Remove unnecessary import & update imports --- ci2v.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci2v.py b/ci2v.py index 44af96b..bef2923 100644 --- a/ci2v.py +++ b/ci2v.py @@ -8,10 +8,9 @@ import cv2 from sys import stdout -from itertools import izip from skimage import color -from skimage.measure import structural_similarity as ssim +from skimage.metrics import structural_similarity as ssim #record start time From 369c5af29e1b0b1e8f263b316ec48a59c0ad0b9c Mon Sep 17 00:00:00 2001 From: intrigus Date: Tue, 23 Nov 2021 16:48:07 +0100 Subject: [PATCH 4/4] Use modern API for current time. --- ci2v.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci2v.py b/ci2v.py index bef2923..9cf0dc6 100644 --- a/ci2v.py +++ b/ci2v.py @@ -14,7 +14,7 @@ #record start time -start = time.clock() +start = time.process_time() #ignore non-contiguous skimage warning warnings.filterwarnings("ignore", module="skimage") @@ -44,7 +44,7 @@ def parse_video(image, video, n_matches, break_point=False, verbose=False): frame_count = 0 #get current time - fps_time = time.clock() + fps_time = time.process_time() cap = cv2.VideoCapture(video) while(cap.isOpened()): @@ -80,7 +80,7 @@ def parse_video(image, video, n_matches, break_point=False, verbose=False): similarities = similarities[:n_matches] #calculate fps - fps = frame_count / (time.clock() - fps_time) + fps = frame_count / (time.process_time() - fps_time) #feedback to cli stdout.write('\r@ %d [%sfps] | best: %d (%s) \r' @@ -203,7 +203,7 @@ def main(): if args.output: save_frame(args.output, n, d['image']) - seconds_taken = time.clock() - start + seconds_taken = time.process_time() - start time_taken = str(datetime.timedelta(seconds=seconds_taken)) print('\n--time taken: \n%s\n' % time_taken)