1

I'm learning OpenCV and Python. I captured some images from my webcam and saved them. But they are saved by default into the local folder. I want to save them to another folder from direct path. How can I do that?

I tried this code

import cv2
import os
img = cv2.imread('image.jpg', 1)
path = 'C:\\Users\MJ-INFO\Desktop\amaster\test'


cv2.imwrite('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Salim Azak
  • 79
  • 10
rahma amri
  • 11
  • 1
  • 3
  • instead of 'test.jpg' add path there, I think you missed that – Inder Jul 27 '19 at 14:42
  • Possible duplicate of [OpenCV - Saving images to a particular folder of choice](https://stackoverflow.com/questions/41586429/opencv-saving-images-to-a-particular-folder-of-choice) – Salim Azak Jul 27 '19 at 14:58

2 Answers2

0

Kindly look at the following code and see the commented out changes:

import cv2
import os
img = cv2.imread('image.jpg', 1)
path = r'C:\\Users\MJ-INFO\Desktop\amaster\test' #use r here as in windows sometimes there is a Unicode problem


cv2.imwrite(path, img) #use path here
cv2.waitKey(0)
cv2.destroyAllWindows()
Inder
  • 3,711
  • 9
  • 27
  • 42
-1

As mentioned in the comment above, change this line cv2.imwrite(path+'\test.jpg', img)

MazeRunner09
  • 334
  • 2
  • 8