简体   繁体   中英

How do i revert an image back after using np.copy?

def boxing(original_img,predictions)
  newImage = np.copy(original_img)
  for result in predictions:
    .
    .
    .
    return newImage

_, ax = plt.subplots(figsize=(20, 10))
ax.imshow(boxing(imgcv, result))

Hey! I passed a np.copy(image) into the boxing function and returned a newImage. Above is the gist of my code and the ... part is just drawing bounding boxes and overwritting the NewImage. How do i convert the resultant newImage back to it's original form after the function?

_, ax = plt.subplots(figsize=(20, 10))
new_im = Image.fromarray(boxing(imgcv, result))
ax.imshow(new_im)

From what i understand, i am supposed to use Image.fromarray to convert it back but I had no success. I understand this may be a silly question but I appreciate the suggestions!

I found the solution. The issue is that the image is in BGR.

new_im = cv2.cvtColor(boxing(imgcv, result), cv2.COLOR_BGR2RGB)

This essentially converts the image back to RGB. Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM