!wget https://pbs.twimg.com/profile_images/1098476777721266181/r4jtNl9E_400x400.png
--2021-01-10 12:28:36-- https://pbs.twimg.com/profile_images/1098476777721266181/r4jtNl9E_400x400.png Resolving pbs.twimg.com (pbs.twimg.com)... 23.1.106.237, 2600:1480:3000:e5:: Connecting to pbs.twimg.com (pbs.twimg.com)|23.1.106.237|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 130696 (128K) [image/png] Saving to: ‘r4jtNl9E_400x400.png.1’ r4jtNl9E_400x400.pn 100%[===================>] 127.63K --.-KB/s in 0.04s 2021-01-10 12:28:36 (3.05 MB/s) - ‘r4jtNl9E_400x400.png.1’ saved [130696/130696]
import cv2
import matplotlib.pyplot as plt
import matplotlib as mpl
from IPython.display import Image, display
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
img = cv2.imread('r4jtNl9E_400x400.png', cv2.IMREAD_COLOR)
plt.imshow(img)
plt.show()
imgray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
res, thresh = cv2.threshold(imgray, 127, 256, 3)
edges = cv2.Canny(thresh, 100, 200)
method = eval('cv2.THRESH_BINARY')
method
0
def thresh(lb, ub, name):
method = eval(name)
res, thresh = cv2.threshold(imgray, lb, ub, method)
plt.imshow(thresh)
widgets.interact(
thresh,
lb=(1,255,1),
ub=(1,255,1),
name=['cv2.THRESH_BINARY',
'cv2.THRESH_BINARY_INV',
'cv2.THRESH_TRUNC',
'cv2.THRESH_TOZERO',
'cv2.THRESH_TOZERO_INV',
'cv2.THRESH_TRIANGLE',
'cv2.THRESH_BINARY+cv2.THRESH_OTSU']
)
interactive(children=(IntSlider(value=128, description='lb', max=255, min=1), IntSlider(value=128, description…
<function __main__.thresh>
Image('r4jtNl9E_400x400.png')
# res, thresh = cv2.threshold(fig, 127, 256, cv2.THRESH_BINARY)
def view(num1=100, num2=200):
edges = cv2.Canny(thresh, num1, num2)
plt.imshow(edges, cmap='gray')
plt.show()
widgets.interact(
view,
num1=(1,100,1),
num2=(10,300,5)
);
interactive(children=(IntSlider(value=100, description='num1', min=1), IntSlider(value=200, description='num2'…
edges = cv2.Canny(imgray, 20, 40)
plt.imshow(edges)
<matplotlib.image.AxesImage at 0x7efef9788ba8>