Link to home
Start Free TrialLog in
Avatar of Anna Mikhailova
Anna Mikhailova

asked on

Not able to read newly written image

I was actually trying to do read an image, do object detection on it and write a new image that has detected objects marked in it. A new image does indeed get saved in the working directory but I am unable to open it using cv2 or using any of the image displaying softwares on fedora. i tried uploading it to a photo uploading site and it displays properly. I did go through the stack overflow, they say the issue was regarding trying to read a png image using a jpeg reader and as per what i could understand i tried installing libpng but still does not work.Would be grateful if someone could help me with it. Here is the code I have tried:

from imageai.Detection import ObjectDetection
import os
import cv2

execution_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "car.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg"))

for eachObject in detections:
    print(eachObject["name"] + " : " + eachObject["percentage_probability"] )
print(cv2.imshow('detected',imagenew))
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.