Sharedsupport / 2014-11-05-104917-open-cv.sagewsOpen in CoCalc
Author: William A. Stein
License: GNU General Public License v3.0
Description: Examples for support purposes.

SageMathCloud includes the OpenCV computer vision library, which "has more than 47 thousand people of user community and estimated number of downloads exceeding 9 million. Usage ranges from interactive art, to mines inspection, stitching maps on the web or through advanced robotics."

There are many Python tutorials available here.

import numpy as np import cv2 import pylab as plt img = cv2.imread('svr.jpg') edges = cv2.Canny(img,100,200) x=plt.subplot(121),plt.imshow(img,cmap = 'gray') x=plt.title('Original Image'), plt.xticks([]), plt.yticks([]) x=plt.subplot(122),plt.imshow(edges,cmap = 'gray') x=plt.title('Edge Image'), plt.xticks([]), plt.yticks([]) plt.show()
blur = cv2.blur(img,(5,5)) x=plt.subplot(121),plt.imshow(img),plt.title('Original') x=plt.xticks([]), plt.yticks([]) x=plt.subplot(122),plt.imshow(blur),plt.title('Blurred') x=plt.xticks([]), plt.yticks([]) plt.show()
median = cv2.medianBlur(img,5) x=plt.subplot(121),plt.imshow(img),plt.title('Original') x=plt.xticks([]), plt.yticks([]) x=plt.subplot(122),plt.imshow(median),plt.title('Median blur') x=plt.xticks([]), plt.yticks([]) plt.show()