Skip to content
Shrijayan
Go back

OpenCV Experiments: Edge Detection and Object Detection

OpenCV Experiments: Edge Detection and Object Detection

Download original notebook: [OpenCV Experiments.ipynb](/notebooks/OpenCV Experiments.ipynb)

OpenCV Experiments

Combined notebook — sections below are preserved verbatim from their originals.

Untitled0

Merged from Untitled0.ipynb (2021-10-25)

# import the necessary packages
import numpy as np
import argparse
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
	help="path to input image")
ap.add_argument("-p", "--prototxt", required=True,
	help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True,
	help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
	help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])
# load the input image and construct an input blob for the image
# by resizing to a fixed 300x300 pixels and then normalizing it
image = cv2.imread(args["image"])
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0,
	(300, 300), (104.0, 177.0, 123.0))
# pass the blob through the network and obtain the detections and
# predictions
print("[INFO] computing object detections...")
net.setInput(blob)
detections = net.forward()

Copy of Untitled23

Merged from Copy of Untitled23.ipynb (2023-03-10)

import cv2
from google.colab.patches import cv2_imshow
import numpy as np
img=cv2.imread("lambo.jpg")
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cimg=cv2.Canny(gray,150,200)
kernel=np.ones((3,3),np.uint8)
dimg=cv2.dilate(cimg,kernel,iterations=1)
eimg1=cv2.erode(dimg,kernel,iterations=1)
disp=np.hstack((cimg,dimg,eimg1))
cv2_imshow(disp)

Share this post on:

Next Post
Vector Databases: A Survey of the Landscape