0

I have a small problem I can't quite solve and it's been this way for almost a week now. I have an Azure Kinect DK camera, from which I take a live video feed of a space.

On that space I will have an object, and I need to track an area around the object to detect any people that get within that area. I have it set up so I subtract all the background from the video feed except the area I want, and feed that to the Azure Kinect Body Tracker.

The problem is that it takes all the video feed, so it detects everyone the Kinect sees, and not just the ones in the area like I want.

Any help or tip is appreciated, and thanks in advance.

Edit added to provide a mre as requested:

    area_pts_2 = np.array([[340, 200], [1180, 200], [1070, 920], [650, 920]])
 # Segunda área de detección
    imAux_2 = np.zeros(shape=(frame.shape[:2]), dtype=np.uint8)
    imAux_2 = cv2.drawContours(imAux_2, [area_pts_2], -1, (255), -1)

    # Área de detección
    image_area_2 = cv2.bitwise_and(gray, gray, mask=imAux_2)

    cnts_2, _ = cv2.findContours(image_area_2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    for cnt in cnts_2:
        if cv2.contourArea(cnt) > 1000:

            # Pintar cuadrado alrededor de contorno detectado
            x, y, w, h = cv2.boundingRect(cnt)
            cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)

            body_frame = bodyTracker.update()
            numberOfBodies = pykinect.Frame.get_num_bodies(body_frame)
            numBodies = str(numberOfBodies)

            combined_image = body_frame.draw_bodies(image_area_2, pykinect.K4A_CALIBRATION_TYPE_COLOR)

So this is the base of what I'm working on. I haven't included the portions of code where I try to crop the image to then feed it to the bodyTracker because they don't work, they make the program crash.

Vadci
  • 1
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jun 28 '22 at 13:13
  • How is the area you want defined? Do you have coordinates? Do you need to detect the object first and select from distance from that? Please clarify. – beaker Jun 28 '22 at 13:51
  • Hello @beaker, so the area I defined is a trapezoid geometrical shape, to allow for depth perception in 2D screen. I don't yet have any definite coordinates but that shouldn't matter because as I see it, if it can be done with one set of coordinates, it can be done with any kind of coordinates. And regarding detection, I don't know if you are familiar with Azure Kinect DK's handling of body tracking, but it basically feeds of a video feed/video/capture and then does it magic to detect human shapes, so I would just need to pass this selected and specific area as the whole feed. – Vadci Jun 28 '22 at 14:12
  • do you realize that video frames are numpy arrays? show us a [mre] for the thing you do – Christoph Rackwitz Jun 28 '22 at 14:19
  • @ChristophRackwitz I have edited the question with code. I do realize video frames are numpy arrays, but I think there's a misunderstanding here. I don't want to crop frame by frame of a video, but rather the video feed, the window. English is not my first language so maybe there's a linguistical mistake. I want to reduce the video feed so that the Azure Kinect only detects what's being showed there and not in the entire FOV of the camera, which would be much larger than the small area I want. – Vadci Jun 28 '22 at 14:40
  • ah, so you're asking about this device and its API, if it has any... and you're saying you don't actually "get a frame" *and then* hand it to some detection API, but that this happens at once, without any way for you to affect that? -- because if you do get a frame **and then** pass it to a detection API, you can trivially crop that frame before giving it to detection – Christoph Rackwitz Jun 28 '22 at 15:21
  • As it was mentioned already, the video frames from OpenCV (using the Python API) are numpy arrays. You could simply crop it by indexing. See: https://stackoverflow.com/questions/39382412/crop-center-portion-of-a-numpy-image – fabda01 Jun 28 '22 at 15:43

0 Answers0