-2

I'm new in OpenCV. I'm trying to save the detected object into a new image.

What should I do?

This is the code I copied from a tutorial:

import cv2
import numpy as np
tric_cascade = cv2.CascadeClassifier('cascade.xml')

img = cv2.imread('anthon18c.png')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

tric = tric_cascade.detectMultiScale(gray,1.01,7)
for (x,y,w,h) in tric:
    img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)


cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
j.doe
  • 662
  • 4
  • 19
  • select code and use button `{}` to correctly format it. – furas Apr 14 '19 at 05:16
  • don't put question in title. Question should be in body. – furas Apr 14 '19 at 05:17
  • if you found code in tutorial then maybe you can find in the same tutorial how to save it. Or find documentation for `cv2` in python. It uses `imread`, `imshow`, so it can be something like `im...` – furas Apr 14 '19 at 05:19

1 Answers1

0

If you want to save image named img, you can use:

cv2.imwrite('/path/to/destination/image.png', img)
Harshil Shah
  • 142
  • 2
  • 3
  • 13