Fixing AVCaptureDeviceTypeExternal Warning in Python Script after macOS Sonoma Update

68 views Asked by At

I'm working with a Python script on my MacBook Pro M2 (macOS Sonoma 14.3.1) that uses OpenCV for face detection and controls an Arduino based on the detection results. This script previously worked on both my Windows laptop and the same MacBook before updating to macOS Sonoma 14.3.1. However, after the update, I encounter the following warning when the script tries to access the camera:

python[9050:443412] WARNING: AVCaptureDeviceTypeExternal is deprecated for Continuity Cameras. Please use AVCaptureDeviceTypeContinuityCamera and add NSCameraUseContinuityCameraDeviceType to your Info.plist.

Despite searching online and finding others with similar issues post-update, I haven't found a clear solution. Could someone guide me on how to resolve this warning? I'm relatively new to macOS development and unsure how to address deprecation warnings or modify the Info.plist for a Python script. Any advice or workaround would be greatly appreciated.

Attempts to Solve:

Searched for similar issues online but found no direct solutions. Checked if the issue is related to OpenCV or macOS compatibility but couldn't pinpoint the problem. Thanks

import serial.tools.list_ports
import cv2
import serial
import numpy as np
# Initialize serial communication with Arduino
ports = serial.tools.list_ports.comports()
portsList = []

for onePort in ports:
    portsList.append(str(onePort))
    print(str(onePort))

val = "/dev/cu.SLAB_USBtoUART"  #  Arduino port
serialInst = serial.Serial()
portVar = None

for x in range(0, len(portsList)):
    if portsList[x].startswith(str(val)):
        portVar = str(val)

if portVar is None:
    print("Arduino port not found. Exiting.")
    exit()

serialInst.baudrate = 9600
serialInst.port = portVar
serialInst.open()

# Initialize face detection using Haar Cascade
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)

last_command = "l"

while True:
    # Read a frame from the webcam
    ret, frame = cap.read()

    # Convert the frame to grayscale for face detection
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Detect faces in the frame
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)

    if len(faces) > 0 and last_command == 'l':
        print("Face detected. Sending 'h' to Arduino.")
        serialInst.write('h'.encode('utf-8'))
        last_command = 'h'
    elif len(faces) == 0 and last_command == 'h':
        print("No face detected. Sending 'l' to Arduino.")
        serialInst.write('l'.encode('utf-8'))
        last_command = 'l'

    # Display the frame with face rectangles
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)

    cv2.imshow('Face Detection', frame)

    # Break the loop if 'exit' is entered
    if cv2.waitKey(1):
        break

# Release resources
cap.release()
cv2.destroyAllWindows()
serialInst.close()
0

There are 0 answers