Skip to main content

Posts

Showing posts from March, 2018

FPS counter with OpenCV

Showing FPS on the screen is an important part of benchmarking your app. In this post we're going to look at how to calculate the number of frames per second and show it on screen. The theory is that we keep track of the last 5 or so timestamps and average over to get the FPS. We keep deleting the last item so the list only has 5 times in it. Lets have a look at the code: 1: import time 2: 3: times = [] 4: count = 5 5: 6: times.append(time.time()) 7: if len(times) >= count: 8: times = times[-count:] 9: fps = "%.2f FPS" % (count/(times[-1] - times[0])) 10: cv2.putText(frame, fps, (0, 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1, cv2.LINE_AA) First import time, which is required for this to work. Then I define two constants which will be used in the function. Remember this code will run every time the videoloop runs, it adds the time to the list. If the list gets too long, get the last bit using indexing. Then work out the av

Opening Files with your Python application

For a long time now I couldn't find any help online for my problem. I want to make my own image viewer, since the one that comes with Windows 10 is so bad, but I want to be able to right click on any image, and select open with my Python application. . Lets take a look at my simple program: 1: import sys 2: 3: try: 4: print(sys.argv[1]) 5: except IndexError: 6: print("Being run without file selected.") 7: 8: input("\n\nPress any key to exit...") I want to just get a simple program working first, i'll build the application later. Normally argv would be used to parse command line arguments into a program but it turns out that when your program is compiled, when you use 'open with' your program, the second argument will be set to the path to which the file is located. The first argument is the name of the program. So the program prints the second argument. If there isn't one, if the program is just run, the