Someone suggested this but it DOESN'T work either.

In the line AVCaptureDevice.requestAccess (for: .video), the parenthesis around for: .video should be removed as it is not a valid syntax in Python. Instead, you should separate the keyword argument for and its value .video with a comma.

In the line AVCaptureDevice.authorizationStatus, the dot notation is not correct. You should use the square brackets notation to access the authorizationStatus attribute of the AVCaptureDevice class.

Here is my code:

import cv2
import numpy as np
from AVFoundation import AVCaptureDevice

class Camera(object):
    def __init__(self, camera=0):
        AVCaptureDevice.requestAccess(for: .video) { granted in
            if granted:
                self.cam = cv2.VideoCapture(camera)
                self.valid = False
                try:
                    resp = self.cam.read()
                    self.shape = resp[1].shape
                    self.valid = True
                except:
                    self.shape = None
            else:
                print("Permission to access camera was denied.")
                self.valid = False
        }

    def get_frame(self):
        if self.valid:
            _, frame = self.cam.read()
        else:
            frame = np.ones((480, 640, 3), dtype=np.uint8)
            col = (0, 256, 256)
            cv2.putText(frame, "(Error: Camera not accessible)",
                        (65, 220), cv2.FONT_HERSHEY_PLAIN, 2, col)
        return frame

    def release(self):
        self.cam.release()

Help me to resolve this "syntax error" so I can compile the code to execute a functional py2app.

0

There are 0 best solutions below