Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounding box colours and saving output #5

Open
abc1110 opened this issue May 11, 2020 · 4 comments
Open

Bounding box colours and saving output #5

abc1110 opened this issue May 11, 2020 · 4 comments

Comments

@abc1110
Copy link

abc1110 commented May 11, 2020

Is it possible to to modify the code so that the bounding boxes too can get different colours as per the violation?
It would also be nice if the final output of the analyzer can be saved locally, by writing a video file in real time.

@aqeelanwar
Copy link
Owner

Yes it can be done.

The video file is being written in realtime.

@abc1110
Copy link
Author

abc1110 commented May 12, 2020

Thanks, I saw the video output getting saved.

I am trying to figure out how to get the bounding boxes coloured as well, and I made the following modification to the code, but I'm afraid the output is not right. The colours for the bounding boxes are not changing as they should wrt distance. Could you suggest where am I going wrong?

def plot_pedestrian_boxes_on_image(frame, pedestrian_boxes, close_p, danger_p):
    frame_h = frame.shape[0]
    frame_w = frame.shape[1]
    thickness = 2
    color_red =  (0, 0, 255)
    color_yellow =  (0, 170, 170)
    color_green = (0, 255, 0)

    for i in range(len(pedestrian_boxes)):
        pt1 = (
                int(pedestrian_boxes[i][1] * frame_w),
                int(pedestrian_boxes[i][0] * frame_h),
                )
        pt2 = (
                int(pedestrian_boxes[i][3] * frame_w),
                int(pedestrian_boxes[i][2] * frame_h),
                )
        print(pt1, pt2)
        print(pedestrian_boxes[i][1], int(pedestrian_boxes[i][0]))
        if i in list(set(chain(*close_p))):
            image = cv2.rectangle(frame, pt1, pt2, color_yellow, thickness)
            cv2.putText(image, str(i), (int(pt1[0]), int(pt1[1]-10)),
                                           cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 170, 170), 2)
        elif i in list(set(chain(*danger_p))):
            image = cv2.rectangle(frame, pt1, pt2, color_red, thickness)
            cv2.putText(image, str(i), (int(pt1[0]), int(pt1[1]-10)),
                                           cv2.FONT_HERSHEY_SIMPLEX, 0.9,  (0, 0, 255), 2)
        else:
            image = cv2.rectangle(frame, pt1, pt2, color_green, thickness)
            cv2.putText(image, str("this is samep"), (int(pt1[0]), int(pt1[1]-10)),
                                           cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)


    return image

@ZIKO94ZIKO
Copy link

Hi @abc1110 hope you are doing well, tell me you please you found the solution about how to get the bounding boxes colored as well , please if send me your modification. thanks in advance.

@ZIKO94ZIKO
Copy link

@abc1110 any update .i have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants