Skip to content
Snippets Groups Projects
Commit 0e0766c3 authored by Quentin Bolsee's avatar Quentin Bolsee
Browse files

edge detection examples

parent 1a5e053f
Branches
No related tags found
No related merge requests found
.idea
\ No newline at end of file
code/img/neil.jpg

113 KiB

code/img/polite_cat.png

219 KiB

import cv2
import numpy as np
import matplotlib.pyplot as plt
def main():
# img = cv2.imread("img/polite_cat.png", cv2.IMREAD_UNCHANGED)
img = cv2.imread("img/neil.jpg", cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
print(img.shape)
edges = cv2.Canny(img, 40, 80)
# ret, th = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# # plt.figure()
# # plt.hist(img.flatten(), bins=np.linspace(0, 255, 100))
# # plt.show()
#
# plt.subplot(121)
# plt.imshow(img, cmap="gray")
# plt.subplot(122)
# # plt.imshow(edges, cmap="gray")
# plt.imshow(img < th, cmap="gray")
# plt.show()
cv2.imshow("test", img)
cv2.waitKey()
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if __name__ == "__main__":
main()
import numpy as np
import cv2
import tqdm
import argparse
def parse_arguments():
usage_text = (
"Usage: python crop_svg.py [options]"
)
parser = argparse.ArgumentParser(description=usage_text)
parser.add_argument("-i", "--input", type=str, required=True, help="Input npy file.")
parser.add_argument("-s", "--slice", type=int, required=True, help="Slice.")
parser.add_argument("-o", "--output", type=str, required=True, help="Input video file.")
return parser.parse_known_args()
def main():
filename_in = "img/pictured_cat.png"
filename_out = "test.mp4"
vid_writer = None
img = cv2.imread(filename_in, cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h, w = img.shape
threshold_values = np.arange(200)
for i in tqdm.tqdm(range(len(threshold_values))):
thresh = threshold_values[i]
if vid_writer is None:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
vid_writer = cv2.VideoWriter(filename_out, fourcc, 60, (w, h))
edges = cv2.Canny(img, thresh//2, thresh)
vid_writer.write(cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR))
vid_writer.release()
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment