1

現在、次のスクリプトは完全に正常に動作しますが、各長方形のバインドされたボックスに識別子を付けたいと考えています。

while True:
    # grab the current frame and initialize the occupied/unoccupied
    (grabbed, frame) = camera.read()

    if not grabbed:
        break

    # resize the frame, convert it to grayscale, and blur it
    frame = imutils.resize(frame, width=500)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (21, 21), 0)

    # if the first frame is None, initialize it
    if firstFrame is None:
        firstFrame = gray
        continue

    # compute the absolute difference between the current frame and
    # first frame
    frameDelta = cv2.absdiff(firstFrame, gray)
    thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]

    # dilate the thresholded image to fill in holes, then find contours
    # on thresholded image
    thresh = cv2.dilate(thresh, None, iterations=2)
    (_, cnts, _) = cv2.findContours(thresh.copy(),   cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

    # loop over the contours
    for c in cnts:
        # if the contour is too small, ignore it

        if cv2.contourArea(c) < args["min_area"]:
            continue

        # compute the bounding box for the contour, draw it on the frame
        (x, y, w, h) = cv2.boundingRect(c)
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

たとえば、次の画像があるとします。

4 つの長方形の境界のそれぞれをオブジェクトとして識別できるようにしたいと考えています。(つまり、左端はダイヤの女王カードのバインドされたボックスで、右端はハートのエース カードのバインドされたボックスです)

今、私はどうしたらこれを達成できるのか途方に暮れており、誰かが私にインスピレーションを与えることができるかどうか疑問に思っています.

4

1 に答える 1

2

あなたがする必要があるのは、連続したフレームの違いを使用して輪郭を見つけ、輪郭全体をループし、座標を注文して各輪郭を個別に検出し、それらにラベルを付けることができます...参考のためにhttp://www.pyimagesearch.com/2016/ 03/21/ordering-coordinates-clockwise-with-python-and-opencv/

于 2016-07-01T09:57:27.753 に答える