1

I am trying to build an auto image Google drive up-loader with raspberry pi and a web-cam but the python script I wrote after executing once properly doesn't seem to work if I execute it again immediately and again starts to work after 10 secs. The same script runs flawlessly on my laptop. Given below is the code I have written. Any help would be appreciated since I don't have any clue why the same code is not working multiple times?

`#!/usr/bin/env python
 import cv2
 import time
 import sys
 import string
 from datetime import datetime
 from pydrive.auth import GoogleAuth
 from pydrive.drive import GoogleDrive

 gauth = GoogleAuth();

 gauth.LoadCredentialsFile('creds.txt');

 if(gauth.credentials is None):
      gauth.LocalWebserverAuth();
 elif(gauth.access_token_expired):
      gauth.Refresh();
else:
      gauth.Authorize();

gauth.SaveCredentialsFile('creds.txt');

drive = GoogleDrive(gauth);

vc = cv2.VideoCapture(0);

if vc.isOpened():
     rval, frame = vc.read();
else:
     rval = False;

fname = 'BillCam';

file_list = drive.ListFile({'q': "'root' in parents and                         trashed=false"}).GetList()
fid = None;

for file1 in file_list:
    if file1['title'] == fname:
    fid = file1['id']

if(fid is None):
    file1 = drive.CreateFile({'title': fname,"mimeType": "  application/vnd.google-apps.folder"})
    file1.Upload();
    fid = file1['id'];

if(rval == True):
   ctime = str(datetime.now().time());
   cv2.imwrite('frame:' + ctime + '.jpg',frame);
   rval, frame = vc.read();
   time.sleep(2);
   file1 = drive.CreateFile({"parents":[{"id": fid}]});
   file1.SetContentFile('frame:' + ctime + '.jpg');
   file1.Upload();`
  • What is the behavior you are seeing the second time it is run? Saying "doesn't seem to work if I execute it again immediately" does not tell anyone what the actual behavior is so we have no idea what could be the problem. Is the program crashing, any error messages, files are not transferred that should have been or what? – Richard Chambers Nov 26 '17 at 1:00
  • I apologize I should have added the details when it's not working but the python program when works perfectly shows me the capturing of the image and uploading process bar etc but the immediate execution does not display any messages not even the capturing and uploading and just ends execution. When I check the dmesg output it shows webcam not interfaced properly error for the immediate next execution – Prathu Baronia Nov 26 '17 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.