-1

I tried to save capture of webcam image in USB using Python on Linux environment.

"Imwrite" is work in file directory but not work in USB directory.

I tried on 'os' package and path.

Is there other method to doing this?

path='/media/odroid/MYUSB/savefolder/'
capture_img=/demo/capture.jpg
image=cv2.imread(capture_img)
cv2.imwrite(os.path.join(path, resave.jpg),image)

The whole code is running without error, but jpg file is not saved in MYUSB

sanghoon
  • 19
  • 3

1 Answers1

0

Perhaps you don't need to use os.join() try this:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
savePath = 'output.jpg' #Replace this with your own path say /media/odroid/MYUSB/savefolder/output.jpg
ret, frame = cap.read()

cv2.imwrite(savePath,frame)

If you want to save the whole video please refer to this answer

Here is the code:

import cv2
import numpy as np


cap = cv2.VideoCapture(0)

savePath = 'output.avi' #Replace this with your own path say /media/odroid/MYUSB/savefolder/output.avi
fourcc = cv2.VideoWriter_fourcc(*'MJPG')

out = cv2.VideoWriter(savePath, fourcc, 20.0, (int(cap.get(3)), int(cap.get(4))))

while True:

    newret, newframe = cap.read()

    cv2.imshow('orig',newframe)
    out.write(newframe)

    k = cv2.waitKey(5) & 0xFF

    if k == 27:
        break

ret, frame = cap.read()

cv2.imwrite(savePath,frame)

cap.release()
out.release()
cv2.destroyAllWindows()

Also, your code has some issues, here is a fixed version of it which should work:

path='/media/odroid/MYUSB/savefolder/'
capture_img='/demo/capture.jpg' #it seems path should be demo/capture.jpg
image=cv2.imread(capture_img)
cv2.imwrite(os.path.join(path, 'resave.jpg'),image)