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 dstack.controls as ctrl | |
import dstack as ds | |
import pandas as pd | |
# import plotly.express as px | |
import plotly.graph_objs as go | |
# from plotly import figure_factory as FF | |
@ds.cache() | |
def get_data(): |
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("Drawing", dc) | |
if chr(key) == "s": | |
show(drawn) | |
d = drawn.copy().astype(np.uint8) | |
r = recognition(cv2.cvtColor(d, cv2.COLOR_BGR2GRAY), 'show') | |
cv2.rectangle(clone, (left, top), (right, bottom), (0, 255, 0), 2) # draw a ROI | |
cv2.imshow("Feed", clone) # show live feed |
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 prediction(img): | |
curr_dir = os.getcwd()+"/dcr/" | |
json_file = open(curr_dir+'cnn2/cnn2.json', 'r') | |
loaded_model_json = json_file.read() # load json and create model | |
json_file.close() | |
loaded_model = model_from_json(loaded_model_json) | |
loaded_model.load_weights(curr_dir+"cnn2/cnn2.h5") # load weights into new model | |
.................................. |
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
..................................................... | |
..................................................... | |
if erase==True: | |
cv2.circle(canvas, (m[0], m[1]), 5, draw_color, -3) | |
erimg=cv2.circle(canvas.copy(), (m[0], m[1]), 5, (0, 0, 0), -3) | |
cv2.circle(c, (m[0], m[1]), 5, (0, 0, 255), -3) | |
e = cv2.erode(erimg, (3, 3), iterations=5) | |
drawn = cv2.resize(e, (clone.shape[1], clone.shape[0])) | |
c = cv2.resize(c, (clone.shape[1], clone.shape[0])) | |
drawn_new = drawn+c |
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
.......................................... | |
........................................... | |
c = np.zeros(canvas.shape, dtype=np.uint8) | |
cv2.circle(c, (m[0], m[1]), 5, pointer_color, -3) | |
cv2.circle(clone, (right+m[0], top+m[1]), 5, pointer_color, -3) | |
if erase==True: | |
cv2.circle(canvas, (m[0], m[1]), 5, draw_color, -3) | |
erimg=cv2.circle(canvas.copy(), (m[0], m[1]), 5, (0, 0, 0), -3) | |
cv2.circle(c, (m[0], m[1]), 5, (0, 0, 255), -3) |
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
........................... | |
.......................... | |
if hand is not None: | |
if chr(key) == "x": # if pressed x, erase | |
draw_color = (255, 255, 255) | |
pointer_color = (0, 0, 255) | |
erase = True | |
if chr(key) == "c": | |
draw_color = (0, 255, 0) | |
pointer_color = (255, 0, 0) |
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.circle(c, (m[0], m[1]), 5, pointer_color, -3) | |
cv2.circle(clone, (right+m[0], top+m[1]), 5, pointer_color, -3) | |
cv2.imshow("mask", thresholded) | |
cv2.imshow("c", c) | |
cv2.circle(canvas, (m[0], m[1]), 5, draw_color, -3) | |
e = cv2.erode(canvas, (3, 3), iterations=5) | |
drawn = cv2.resize(e, (clone.shape[1], clone.shape[0])) |
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 running_average(bg_img, image, aweight): | |
if bg_img is None: | |
bg_img = image.copy().astype("float") | |
else: | |
cv2.accumulateWeighted(image, bg_img, aweight) | |
return bg_img | |
def get_contours(bg_img, image, threshold=10): | |
diff = cv2.absdiff(bg_img.astype("uint8"), image) # abs diff betn img and bg | |
_, th = cv2.threshold(diff, threshold, 255, cv2.THRESH_BINARY) | |
(cnts, _) = cv2.findContours(th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
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
########################### | |
######################## | |
else: # if not to take average | |
num_frames = 0 | |
hand = get_contours(bg_img, gray) # take our segmented hand | |
take_average=False | |
if hand is not None: | |
thresholded, segmented = hand | |
cv2.drawContours(clone, [segmented+(right,top)], -1, (0, 0, 255)) | |
cv2.imshow("mask", thresholded) |
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
........................ | |
........................ | |
else: # if not to take average | |
num_frames = 0 | |
hand = get_contours(bg_img, gray) # take our segmented hand | |
take_average=False | |
if hand is not None: | |
thresholded, segmented = hand | |
cv2.drawContours(clone, [segmented+(right,top)], -1, (0, 0, 255)) | |
cv2.imshow("mask", thresholded) |
NewerOlder