Skip to content

Instantly share code, notes, and snippets.

@chrisvoncsefalvay
Last active June 23, 2016 01:42
Show Gist options
  • Select an option

  • Save chrisvoncsefalvay/e8f10cdd68edac8ffb70f739f8e1acec to your computer and use it in GitHub Desktop.

Select an option

Save chrisvoncsefalvay/e8f10cdd68edac8ffb70f739f8e1acec to your computer and use it in GitHub Desktop.
OpenCV LiveTemplate goodies
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
cv2.imwrite("$FILENAME$", $VARIABLE$)
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
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
cv2.imshow("$WINDOW_TITLE$", $VARIABLE$)
logger.debug(VisualRecord("$MESSAGE$",
$IMGVAR$,
$SUBTITLE$,
fmt="$FMT$"))
logger.info(VisualRecord("$MESSAGE$",
$IMGVAR$,
$SUBTITLE$,
fmt="$FMT$"))
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)
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