Several concepts of "Python" computer vision _ Classical target detection algorithm

Source: Internet
Author: User

Image Pyramid

1. In the from Cv2.resize, when the parameter is passed in the first row

2. Using the generator in Python, use the For I in Pyramid when calling

3.scaleFactor is a scaling factor, you need to ensure that the scaled graph is not less than the minimum size, the corresponding neural network is the training size

"Image Pyramid" def Resize (img, scalefactor):    # Cv2.resize receives the column first, returns the return    Cv2.resize (IMG, (int (img.shape[1)). * (1/scalefactor)),                            Int (img.shape[0] * (1/scalefactor)),                      Interpolation=cv2. Inter_area) def pyramid (image, scale=1.5, minSize = (+)):    yield image    while True:        image = Resize (image, Scale)        if image.shape[0]  < minsize[1] or image.shape[1] < Minsize[0]:            break        yield  image
Sliding window
"Sliding Window" def sliding_window (image, Stepsize, windowsize): For    y in range (0, image.shape[0], stepsize): for        x in Range (0, image.shape[1], stepsize):            yield (x, Y, image[y:y+windowsize[1], x:x+windowsize[0])
Non-maximal value suppression
' ' Non-maximal value suppression ' Def non_max_suppression_fast (boxes, Overlapthresh): # If there is no box, return to the empty list if Len (boxes) = = 0:return [] # Modified boxes format for float convenient handling if boxes.dtype.kind = = ' I ': boxes = boxes.astype (' float ') # Use pick to collect boxes pic k = [] x1 = boxes[:, 0] y1 = boxes[:, 1] x2 = boxes[:, 2] y2 = boxes[:, 3] scores = boxes[:, 4] area = ( X2-X1 + 1) * (Y2-y1 + 1) # Sorted by score from small to large indexes IDXS = Np.argsort (scores) # [::-1], the source program has such a reverse order, but I think it should be removed WH        Ile Len (IDXS) > 0: # assigns the last (lowest score) index to I, and uses pick to collect this index (that is, i), end = Len (IDXS)-1 i = Idxs[last]        Pick.append (i) # in boxes with a score greater than current I, # Find the upper-left and lower-right points of the coincident part xx1 = Np.maximum (X1[i], X1[idxs[:last]) Yy1 = Np.maximum (Y1[i], Y1[idxs[:last]]) xx2 = Np.minimum (X2[i], x2[idxs[:last]) Yy2 = Np.minimum (y2[i        ] (Y2[idxs[:last]]) # Calculates the resulting coincident area w = np.maximum (0, xx2-xx1 + 1) H = np.maximum (0, yy2-yy1 + 1) # Calculate coincidence degree oveRlap = (W * h)/area[idxs[:last] # Delete the item with the highest score (loop started already collected), # delete Idxs = Np.delete (Idxs, Np.concatenate (  ([Last], np.where (overlap > Overlapthresh)))) # [0])) # plus the index only deletes one of the highest-scoring overweight rectangles, so you should not index return boxes[pick].astype (' int ')

Several concepts of "Python" computer vision _ Classical target detection algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.