How to use the imutils.object_detection.non_max_suppression function in imutils

To help you get started, we’ve selected a few imutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HandsomeHans / SVM-classification-localization / 9_SlidingWindow+SVM+NMS_cam.py View on Github external
scales = [(200,200), (300,300)]
#        scales = [(200,200), (250, 250), (300,300)]
        for (winW,winH) in scales:
            for (x, y, window) in sliding_window(image, stepSize=100, windowSize=(winW,winH)):
                result = 0
                if window.shape[0] != winH or window.shape[1] != winW:
                    continue
                if window.shape[0] != 200 or window.shape[1] != 200:
                    window = cv2.resize(window,(200,200),interpolation=cv2.INTER_CUBIC)
                    win_fd = getFeat(window)
                    win_fd.shape = 1,-1
                    result = int(clf.predict(win_fd))
                    if result == 1:
                        rects.append([x, y, x + winW, y + winH])
        rects = np.array(rects)
        pick = non_max_suppression(rects, probs=None, overlapThresh=0.1)
        minx = 10000
        miny = 10000
        maxx = 0
        maxy = 0
        for (xA, yA, xB, yB) in pick:
            if xA < minx:
                minx = xA
            if yA < miny:
                miny = yA
            if xB > maxx:
                maxx = xB
            if yB > maxy:
                maxy = yB
        if (abs(maxx - minx) < image.shape[1]) and (abs(maxy - miny) < image.shape[0]):
            cv2.rectangle(image, (minx, miny), (maxx, maxy), (0, 255, 0), 2)
        cv2.imshow("After NMS", image)
github s-ankur / human-activity-dih18 / demo.py View on Github external
def suppress(boxes, shape):
    rects = rects_from_boxes(boxes, shape)
    picked = non_max_suppression(rects, overlapThresh=.065)
    # print(picked)
    ans = []
    for (x, y, x2, y2) in picked:
        for box in boxes:
            (X, Y, X2, Y2) = box
            if isclose(x, X * shape[0], abs_tol=2) and \
                    isclose(y, Y * shape[1], abs_tol=2) and \
                    isclose(x2, X2 * shape[0], abs_tol=2) and \
                    isclose(y2, Y2 * shape[1], abs_tol=2):
                ans.append(box)
    return ans
github nimotli / SmartAssistantArab / VideoDetect.py View on Github external
(123.68, 116.78, 103.94), swapRB=True, crop=False)
	net.setInput(blob)
	(scores, geometry) = net.forward(layerNames)
 
	# decode the predictions, then  apply non-maxima suppression to
	# suppress weak, overlapping bounding boxes
	(rects, confidences) = decode_predictions(scores, geometry)
	predictedTexts=0
	for val in confidences:
	    if val>0.5:
	       predictedTexts=predictedTexts+1
	
	conf=np.array(confidences)
    #print("the number of words/confidences is: ",str(predictedTexts),"/",str(len(confidences)))
	print("the confidences are :"+str(confidences))
	boxes = non_max_suppression(np.array(rects), probs=confidences)
    
	# loop over the bounding boxes
	for (startX, startY, endX, endY) in boxes:
		# scale the bounding box coordinates based on the respective
		# ratios
		startX = int(startX * rW)-10
		startY = int(startY * rH)-10
		endX = int(endX * rW)+10
		endY = int(endY * rH)+10

		# draw the bounding box on the frame
		cv2.rectangle(orig, (startX, startY), (endX, endY), (125, 255, 35), 2)
    # update the FPS counter
	fps.update()
 
	# show the output frame
github Arkanayan / People-Count / detect.py View on Github external
ret, frame = cap.read()

        # frame1 = frame.clone()
        # frame1 = np.array(frame)

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        gray = imutils.resize(gray )

        (rects, weights) = hog.detectMultiScale(gray, winStride=(4, 4),
                padding=(8, 8), scale=1.05)
        
        # for (x, y, w, h) in rects:
        #     cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
        
        rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
        pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)

        # Write to csv, first column: frame number, 2nd column: no. of peoples
        peoplewriter.writerow([cap.get(1), len(pick)])
        for (xA, yA, xB, yB) in pick:
            cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)
        
        # cv2.imshow('orig', frame)
        # cv2.imshow('non_max', frame)

        # index += 1
        # if index == 500:
        #     break
        out.write(frame)
        
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
github HandsomeHans / SVM-classification-localization / 8_SlidingWindow+SVM+NMS_image.py View on Github external
if window.shape[0] != winH or window.shape[1] != winW:
                continue
            cv2.imshow("asd", window)
            cv2.waitKey(0)
            print window.shape
            if window.shape[0] != 200 or window.shape[1] != 200:
                window = cv2.resize(window,(200,200),interpolation=cv2.INTER_CUBIC)
            win_fd = getFeat(window)
            win_fd.shape = 1,-1
            result = int(clf.predict(win_fd))
            print 'smamll image result is %d' %result
            if result == 1:
                rects.append([x, y, x + winW, y + winH])
                cv2.rectangle(orig, (x, y), (x + winW, y + winH), (0, 0, 255), 2)
    rects = np.array(rects)
    pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)
    for (xA, yA, xB, yB) in pick:
        cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)
    t1 = time.time()
    print 'The cast of time is :%f seconds' % (t1-t0)
    cv2.imshow("Before NMS", orig)
    cv2.imshow("After NMS", image)
    cv2.waitKey(0)
github ITCoders / Human-detection-and-Tracking / main.py View on Github external
def detect_people(frame):
    """
    detect humans using HOG descriptor
    Args:
        frame:
    Returns:
        processed frame
    """
    (rects, weights) = hog.detectMultiScale(frame, winStride=(8, 8), padding=(16, 16), scale=1.06)
    rects = non_max_suppression(rects, probs=None, overlapThresh=0.65)
    for (x, y, w, h) in rects:
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
    return frame
github ITCoders / Human-detection-and-Tracking / main.py View on Github external
def detect_people(frame):
	"""
	detect humans using HOG descriptor
	Args:
		frame:
	Returns:
		processed frame
	"""
	(rects, weights) = hog.detectMultiScale(frame, winStride=(4, 4), padding=(16, 16), scale=1.06)
	rects = non_max_suppression(rects, probs=None, overlapThresh=0.65)
	for (x, y, w, h) in rects:
		cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
	return frame
github ZER-0-NE / EAST-Detector-for-text-detection-using-OpenCV / opencv_text_detection_image.py View on Github external
# compute both the starting and ending (x, y)-coordinates for
        # the text prediction bounding box
        endX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x]))
        endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x]))
        startX = int(endX - w)
        startY = int(endY - h)

        # add the bounding box coordinates and probability score to
        # our respective lists
        rects.append((startX, startY, endX, endY))
        confidences.append(scoresData[x])

# apply non-maxima suppression to suppress weak, overlapping bounding
# boxes
boxes = non_max_suppression(np.array(rects), probs=confidences)

# loop over the bounding boxes
for (startX, startY, endX, endY) in boxes:
    # scale the bounding box coordinates based on the respective
    # ratios
    startX = int(startX * rW)
    startY = int(startY * rH)
    endX = int(endX * rW)
    endY = int(endY * rH)

    # draw the bounding box on the image
    cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 255, 0), 2)

# show the output image
cv2.imshow("Text Detection", orig)
cv2.waitKey(0)
github keplerlab / katna / Katna / image_filters / text_detector.py View on Github external
image = cv2.resize(self.image, (320, 320))
        (H, W) = image.shape[:2]

        # construct a blob from the image and then perform a forward pass of
        # the model to obtain the two output layer sets
        blob = cv2.dnn.blobFromImage(
            self.image, 1.0, (W, H), (123.68, 116.78, 103.94), swapRB=True, crop=False
        )

        self.net.setInput(blob)
        (scores, geometry) = self.net.forward(self.layerNames)

        rects, confidences = self.__decode_predictions(scores, geometry)
        # apply non-maxima suppression to suppress weak, overlapping bounding
        # boxes
        boxes = non_max_suppression(np.array(rects), probs=confidences)
        text_rects = []
        # loop over the bounding boxes
        for (startX, startY, endX, endY) in boxes:
            # scale the bounding box coordinates based on the respective
            # ratios

            startX = int(startX * rW)
            startY = int(startY * rH)
            endX = int(endX * rW)
            endY = int(endY * rH)
            cv2.rectangle(self.image, (startX, startY), (endX, endY), (0, 0, 255), 3)
            text_rects.append([startX, startY, endX, endY])

        text_rects = sorted(text_rects, key=lambda item: item[0])
        final_rects = text_rects
        if len(text_rects) > 0:
github ITCoders / Human-detection-and-Tracking / scripts / car_detect.py View on Github external
image = cv2.imread(imagePath)

# Resize the image so it fits in the screen
image1 = imutils.resize(image, height=500)
gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = car_cascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    # flags = cv2.cv.CV_HAAR_SCALE_IMAGE
    flags=0
)
face = non_max_suppression(faces, probs=None, overlapThresh=0.3)
if format(len(faces)) == 1:
    print("Found {0} face!".format(len(faces)))
else:
    print("Found {0} faces!".format(len(faces)))

# Draw a rectangle around the faces
for (x, y, w, h) in face:
    cv2.rectangle(image1, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.imshow("Faces found", image1)
cv2.waitKey(0)

imutils

A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours, detecting edges, and much more easier with OpenCV and both Python 2.7 and Python 3.

MIT
Latest version published 3 years ago

Package Health Score

64 / 100
Full package analysis