Computer Vision === ###### tags: `IvLabs` --- Aaron Bobick --- - Lecture 1-5 OpenCV Documentation --- - Reading and Displaying Image img = cv2.imread('apple.webp') cv2.imshow('apple', img) - Reading and Displaying Video video = cv2.VideoCapture(0) while True: ret, img = video.read() cv2.imshow("Camera", img) if cv2.waitKey(1) & 0xFF == ord("q"): break - BGR to Grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - BGR to HSV imghsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) - Gaussian Blur imgBlur = cv2.GaussianBlur(result, (7, 7), 1) - Canny Edge Detection imgCanny = cv2.Canny(imgGray, 100, 200) - Image Dialation imgDil = cv2.dilate(imgCanny, kernel, iterations=1) - Image Erosion image = cv2.erode(image, kernel, iterations=1) - Creating Trackbar def empty(x): pass cv2.namedWindow("HSV Value") cv2.resizeWindow("HSV Value", 360, 240) cv2.createTrackbar("Hue min", "HSV Value", 0, 179,empty) - Getting Trackbar Value (Inside Loop) h_min = cv2.getTrackbarPos("Hue min", "HSV Value") Youtube(Murtaza's Workshop) --- - https://www.youtube.com/@murtazasworkshop/playlists - Finding Contours and Centre: def getContours(img, imgcnt): cnt, hier = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) for c in cnt: area = cv2.contourArea(c) if area>500 : cv2.drawContours(imgcnt, c, -1, (0,0,255), 5) perimeter = cv2.arcLength(c, True) edges = cv2.approxPolyDP(c, 0.02*perimeter, True) x, y, w, h = cv2.boundingRect(edges) cv2.rectangle(imgcnt, (x, y), (x+w, y+h), (0, 255, 0), 5) M = cv2.moments(c) if M['m00'] != 0 : cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) cv2.circle(imgcnt, (cx, cy), 5, (255, 0, 0), 3) - Creating a mask: lower = np.array([h_min, s_min, v_min]) upper = np.array([h_max, s_max, v_max]) filt = cv2.inRange(imghsv, lower, upper) result = cv2.bitwise_and(img, img, mask=filt)
{"metaMigratedAt":"2023-06-17T16:51:22.477Z","metaMigratedFrom":"Content","title":"Computer Vision","breaks":true,"contributors":"[{\"id\":\"8b7bde11-6e40-4bba-ace6-23bf2f0db963\",\"add\":2339,\"del\":10}]"}
Expand menu