Last active
June 23, 2016 01:42
-
-
Save chrisvoncsefalvay/e8f10cdd68edac8ffb70f739f8e1acec to your computer and use it in GitHub Desktop.
OpenCV LiveTemplate goodies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def process_with_fps($IMAGE$, processing_function=process): | |
| global start, end | |
| imgbuff = processing_function($IMAGE$) | |
| end = time.time() | |
| framerate = 1/(end - start) | |
| cv2.putText(imgbuff, "{framerate:.2f} fps".format(framerate=framerate), (50,50), cv2.FONT_HERSHEY_PLAIN, 1, (255,255,255), 2) | |
| start = end | |
| return imgbuff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cv2.imwrite("$FILENAME$", $VARIABLE$) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import imutils | |
| import argparse | |
| import cv2 | |
| def $PROCESSING_FUNCTION$(frame): | |
| # Put your image processing code here... | |
| return frame | |
| vc = cv2.VideoCapture(0) | |
| while True: | |
| _, imgbuff = vc.read() | |
| primage = $PROCESSING_FUNCTION$(imgbuff) | |
| cv2.imshow("$WINDOW_TITLE$", primage) | |
| k = cv2.waitKey(30) & 0xFF | |
| if k == 27: | |
| vc.release() | |
| cv2.destroyAllWindows() | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import imutils | |
| import argparse | |
| import cv2 | |
| def $PROCESSING_FUNCTION$(frame): | |
| # Put your image processing code here... | |
| return frame | |
| # Construct argument parser & parse arguments | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("-i", "--image", help="Path to the image") | |
| args = vars(ap.parse_args()) | |
| if args["image"]: | |
| imgbuff = cv2.imread(args["image"]) | |
| else: | |
| vc = cv2.VideoCapture(0) | |
| while True: | |
| if args["image"]: | |
| cv2.imshow("Original", imgbuff) | |
| else: | |
| _, imgbuff = vc.read() | |
| primage = $PROCESSING_FUNCTION$(imgbuff) | |
| cv2.imshow("$WINDOW_TITLE$", primage) | |
| k = cv2.waitKey(30) & 0xFF | |
| if k == 27: | |
| if isdefined(vc): | |
| vc.release() | |
| cv2.destroyAllWindows() | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cv2.imshow("$WINDOW_TITLE$", $VARIABLE$) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| logger.debug(VisualRecord("$MESSAGE$", | |
| $IMGVAR$, | |
| $SUBTITLE$, | |
| fmt="$FMT$")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| logger.info(VisualRecord("$MESSAGE$", | |
| $IMGVAR$, | |
| $SUBTITLE$, | |
| fmt="$FMT$")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from logging import FileHandler | |
| from vlogging import VisualRecord | |
| import logging | |
| # Open logging file | |
| logger = logging.getLogger("$LOGGER_NAME$") | |
| fh = FileHandler("$LOGGER_FILENAME$.html", mode="w") | |
| # Set logger attributes | |
| logger.setLevel(logging.$LOGGING_LEVEL$) | |
| logger.addHandler(fh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| logger.warning(VisualRecord("$MESSAGE$", | |
| $IMGVAR$, | |
| $SUBTITLE$, | |
| fmt="$FMT$")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment