Save detected image to disk

Hi,

I want to alter detectnet.py so that a picture (including the frame) of a detected object is saved to disk.
At the moment, this part of the code captures the image from the camera and checks if a keyboard (for testing) is detected.
It then sends me a message via telegram:

while True:
	# capture the next image
	img = input.Capture()

	# detect objects in the image (with overlay)
	detections = net.Detect(img, overlay=opt.overlay)

	# print the detections
	print("detected {:d} objects in image".format(len(detections)))

	for detection in detections:
		print(detection)

	# render the image
	output.Render(img)

	# update the title bar
	output.SetStatus("{:s} | Network {:.0f} FPS".format(opt.network, net.GetNetworkFPS()))

    for detection in detections:
        if detection.ClassID == 76:
	        i = i + 1
            if i > 30:
                bot.send_video(chat_id="", photo=open('/tmp/output.mp4', 'rb'), caption="mycaption")
                os.remove('/tmp/output.mp4')
                i = 0

	# exit on input/output EOS
	if not input.IsStreaming() or not output.IsStreaming():
		break

The ultimate goal is to send me an image of the detected object via telegram, but I can’t get my head around how to render just the last frame and send it as a jpeg.
If it is easier, a video would also be okay.

Can anybody point me in the right direction?
Thanks :)

Hi,

Suppose you should be able to save the img data into a jpeg file directly with cv2.imwrite().
https://docs.opencv.org/4.1.1/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce

Thanks.

Hi,
thanks for your answer.
I looked into it and while playing around, I noticed that my solution was already pretty close.
It works now as expected :)