Merge "Making image_capture.py executable."
diff --git a/y2020/vision/tools/python_code/image_capture.py b/y2020/vision/tools/python_code/image_capture.py
old mode 100644
new mode 100755
index d6ce6d7..81349bc
--- a/y2020/vision/tools/python_code/image_capture.py
+++ b/y2020/vision/tools/python_code/image_capture.py
@@ -1,34 +1,52 @@
+#!/usr/bin/python3
+
 import cv2
 import datetime
-# Open the device at the ID X for /dev/videoX
-CAMERA_INDEX = 0
-cap = cv2.VideoCapture(CAMERA_INDEX)
+import sys
 
-#Check whether user selected camera is opened successfully.
-if not (cap.isOpened()):
-    print("Could not open video device /dev/video%d" % CAMERA_INDEX)
-    quit()
+import gflags
+import glog
 
-while True:
-    # Capture frame-by-frame
-    ret, frame = cap.read()
+FLAGS = gflags.FLAGS
 
-    exp = cap.get(cv2.CAP_PROP_EXPOSURE)
-    #print("Exposure:", exp)
-    # Display the resulting frame
-    cv2.imshow('preview', frame)
 
-    #Waits for a user input to capture image or quit the application
-    keystroke = cv2.waitKey(1)
+def main(argv):
+    # Open the device at the ID X for /dev/videoX
+    # NOTE: if camera_reader is running, it will need to be stopped
+    # since it will have control of the camera.
+    CAMERA_INDEX = 0
+    cap = cv2.VideoCapture(CAMERA_INDEX)
 
-    if keystroke & 0xFF == ord('q'):
-        break
-    elif keystroke & 0xFF == ord('c'):
-        image_name = datetime.datetime.today().strftime(
-            "capture-%Y-%m-%d-%H-%M-%S.png")
-        print("Capturing image as %s" % image_name)
-        cv2.imwrite(image_name, frame)
+    # Check whether user selected camera is opened successfully.
+    if not (cap.isOpened()):
+        print("Could not open video device /dev/video%d" % CAMERA_INDEX)
+        return
 
-# When everything's done, release the capture
-cap.release()
-cv2.destroyAllWindows()
+    while True:
+        # Capture frame-by-frame
+        ret, frame = cap.read()
+
+        exp = cap.get(cv2.CAP_PROP_EXPOSURE)
+        #print("Exposure:", exp)
+        # Display the resulting frame
+        cv2.imshow('preview', frame)
+
+        # Wait for a user input to capture image or quit the application
+        keystroke = cv2.waitKey(1)
+
+        if keystroke & 0xFF == ord('q'):
+            break
+        elif keystroke & 0xFF == ord('c'):
+            image_name = datetime.datetime.today().strftime(
+                "capture-%Y-%m-%d-%H-%M-%S.png")
+            print("Capturing image as %s" % image_name)
+            cv2.imwrite(image_name, frame)
+
+    # When everything's done, release the camera
+    cap.release()
+    cv2.destroyAllWindows()
+
+
+if __name__ == '__main__':
+    argv = FLAGS(sys.argv)
+    sys.exit(main(argv))