| Hosted by CoCalc | Download
#import sage_server #sage_server.MAX_OUTPUT_MESSAGES = 100000000000000 import random import string import os import cv2 def inline_image_container(name): html('<img src="" id="%s" />' % (name), hide=False) def show_inline_image(container, file_path): url = salvus.file(file_path, show=False).url html("<script>$('#%s').attr('src', '%s')" % (container, url), hide=False) def cv_inline_show(container, img): random_filename = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20))+'.jpg' cv2.imwrite(random_filename, img) show_inline_image(container, random_filename) os.remove(random_filename)
import glob import numpy as np import cv2 import time videos = [''] + glob.glob('*.mp4') @interact def f(video=videos): if not video: return inline_image_container('frame') cap = cv2.VideoCapture(video) while True: ret, frame = cap.read() # Display the resulting frame cv_inline_show('frame',frame) #show_inline_image('frame', 'frame.jpg') #url = salvus.file('frame.jpg', show=False).url #html("<script>$('#frame').attr('src', '%s')" % url) time.sleep(1)
Interact: please open in CoCalc
import sage_server sage_server.MAX_OUTPUT_MESSAGES = 100000000000000 import glob import numpy as np import cv2 import time # import the necessary packages import numpy as np import argparse import glob import cv2 import imutils def auto_canny(image, sigma=0.33): # compute the median of the single channel pixel intensities v = np.median(image) # apply automatic Canny edge detection using the computed median lower = int(max(0, (1.0 - sigma) * v)) upper = int(min(255, (1.0 + sigma) * v)) edged = cv2.Canny(image, lower, upper) # return the edged image return edged videos = [''] + glob.glob('*.mp4') @interact def f(video=videos): if not video: return containers = ['raw', 'canny', 'gray', 'gray_canny'] for container in containers: inline_image_container(container) cap = cv2.VideoCapture(video) while True: ret, frame = cap.read() frame = imutils.resize(frame, width=360) canny = auto_canny(frame) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray_canny = auto_canny(auto_canny(auto_canny(gray))) gray_blurred = cv2.GaussianBlur(gray, (21, 21), 0) gray_blurred_canny = auto_canny(gray_blurred) what_to_show = [frame, canny, gray, gray_canny] for item in zip(containers, what_to_show): cv_inline_show(*item) time.sleep(1)
Interact: please open in CoCalc
import sage_server sage_server.MAX_OUTPUT_MESSAGES = 100000000000000 import glob import numpy as np import cv2 import time # import the necessary packages import numpy as np import argparse import glob import cv2 import imutils def auto_canny(image, sigma=0.33): # compute the median of the single channel pixel intensities v = np.median(image) # apply automatic Canny edge detection using the computed median lower = int(max(0, (1.0 - sigma) * v)) upper = int(min(255, (1.0 + sigma) * v)) edged = cv2.Canny(image, lower, upper) # return the edged image return edged videos = [''] + glob.glob('*.mp4') @interact def f(video=videos): if not video: return containers = ['gray', 'gray_canny', 'frame_delta'] for container in containers: inline_image_container(container) cap = cv2.VideoCapture(video) last_frame = None while True: ret, frame = cap.read() frame = imutils.resize(frame, width=360) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray_canny = auto_canny(gray) if not last_frame: last_frame = gray continue gray_blurred = cv2.GaussianBlur(gray, (21, 21), 0) gray_blurred_canny = auto_canny(gray_blurred) #frameDelta = cv2.absdiff(last_frame, gray_canny) #thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1] what_to_show = [gray, gray_canny, thresh] for item in zip(containers, what_to_show): cv_inline_show(*item) last_frame = gray time.sleep(1)
Interact: please open in CoCalc
cv2.bilateralFilter?
File: Unable to read docstring (source code not available)
import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('home_6.jpg',0) laplacian = cv2.Laplacian(img,cv2.CV_64F) sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) cv2.imwrite('laplacian.jpg', laplacian) salvus.file('laplacian.jpg') cv2.imwrite('sobelx.jpg', sobelx) salvus.file('sobelx.jpg') cv2.imwrite('sobely.jpg', sobely) salvus.file('sobely.jpg')
True
True
True
import numpy as np import cv2 img = cv2.imread('home_6.jpg') def auto_canny(image, sigma=0.33): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.bilateralFilter(gray,9,75,75) # compute the median of the single channel pixel intensities v = np.median(image) # apply automatic Canny edge detection using the computed median lower = int(max(0, (1.0 - sigma) * v)) upper = int(min(255, (1.0 + sigma) * v)) edged = cv2.Canny(image, lower, upper) # return the edged image return edged img2 = cv2.bilateralFilter(img,9,75,75) for i in range(10): img2 = cv2.bilateralFilter(img2,9,75,75) cv2.imwrite('test.jpg', auto_canny(img2)) salvus.file('test.jpg')
True