Filling holes inside a binary object

There are two methods to do this: 1) Contour Filling: First, invert the image, find contours in the image, fill it with black and invert back. des = cv2.bitwise_not(gray) contour,hier = cv2.findContours(des,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE) for cnt in contour: cv2.drawContours(des,[cnt],0,255,-1) gray = cv2.bitwise_not(des) Resulting image: 2) Image Opening: kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) res = cv2.morphologyEx(gray,cv2.MORPH_OPEN,kernel) The resulting image is … Read more

Capturing a single image from my webcam in Java or Python

@thebjorn has given a good answer. But if you want more options, you can try OpenCV, SimpleCV. using SimpleCV (not supported in python3.x): from SimpleCV import Image, Camera cam = Camera() img = cam.getImage() img.save(“filename.jpg”) using OpenCV: from cv2 import * # initialize the camera cam = VideoCapture(0) # 0 -> index of camera s, … Read more

tech