dropdown menu

Back To Home

Friday, November 15, 2019

python- control android camera

Control camera using module for python and transfer picture direct to pc.
Applicable to window or linux environment.
In order to call command prompt we need to import os.
module shutil mainly used to copy file.
tkinter is used to write gui.
adb shell are the adroid command.

following command to install ADB in linux: 
sudo apt-get install adb

Don't forget to enable phone in usb debugging mode.
https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm

Python code:
from tkinter import *
import os
import shutil

root=Tk()

def preview():
    os.system('adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA"')
 
def capture():
    os.system('adb shell input keyevent 27')
 
def focus():
    os.system('adb shell "input keyevent KEYCODE_FOCUS"')
 
def copy():
    os.system('adb pull /sdcard/DCIM/Camera/ /home/pi/Desktop/')
 
    os.system('adb shell rm -rf /sdcard/DCIM/Camera/*')
    os.system('adb shell mount -o remount,rw /sdcard')
    for file in os.listdir("/home/pi/Desktop/Camera"):
        newfile = "/home/pi/Desktop/Camera/image.png"
        shutil.move(os.path.join("/home/pi/Desktop/Camera",file),newfile)
 
 
a=Button(root,text="preview",command=preview,height=3,width=10)
a.grid()
b=Button(root,text="capture",command=capture,height=3,width=10)
b.grid()
d=Button(root,text="focus",command=focus,height=3,width=10)
d.grid()
e=Button(root,text="copy",command=copy,height=3,width=10)
e.grid()

root.mainloop()

Part1:
                                          

Part2:                              

                                  

                                                 

No comments:

Post a Comment