Skip to content

Instantly share code, notes, and snippets.

@willwade
Created November 6, 2024 00:08
Show Gist options
  • Save willwade/7cadb98d9590b9aac71aa3e76f4f2f5d to your computer and use it in GitHub Desktop.
Save willwade/7cadb98d9590b9aac71aa3e76f4f2f5d to your computer and use it in GitHub Desktop.
test nukita and mediapipe
@echo off
setlocal
rem Capture the Poetry environment path
for /f "delims=" %%i in ('poetry env info --path') do set venv_path=%%i
rem Construct the site-packages path
set site_packages=%venv_path%\Lib\site-packages
rem Convert the path to forward slashes for Nuitka compatibility
set site_packages=%site_packages:\=/%
rem Initialize SIGNED_FLAG to 0 (unsigned by default)
set SIGNED_FLAG=0
rem Loop through the arguments and check if --signed is present
for %%a in (%*) do (
if "%%a"=="--signed" (
set SIGNED_FLAG=1
)
)
rem Set the UAC_FLAG conditionally based on --signed flag
set UAC_FLAG=
if %SIGNED_FLAG%==1 (
set UAC_FLAG=--windows-uac-uiaccess
)
rem Capture the Python version from the Poetry environment
for /f "delims=" %%v in ('poetry run python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')"') do set python_version=%%v
rem Echo the constructed site-packages path and Python version for debugging
echo Site packages path: %site_packages%
echo Python version: %python_version%
rem Compile with Nuitka
poetry run python -m nuitka ^
--standalone ^
--onefile ^
--windows-icon-from-ico=assets/images/icon.ico ^
%UAC_FLAG% ^
--output-dir=dist ^
--enable-plugin=tk-inter ^
--nofollow-import-to=unittest ^
--nofollow-import-to=setuptools ^
--include-data-dir=assets=assets ^
--include-data-dir=configs=configs ^
--include-data-dir="%site_packages%/mediapipe/modules=mediapipe/modules" ^
--include-package=mediapipe ^
--include-data-file="%site_packages%/mediapipe/python/_framework_bindings.cp%python_version%-win_amd64.pyd=mediapipe/python/_framework_bindings.cp%python_version%-win_amd64.pyd" ^
--include-module=comtypes ^
--include-module=comtypes.stream ^
--include-module=comtypes.client ^
--assume-yes-for-downloads ^
main.py
endlocal
import cv2
import mediapipe as mp
# Initialize Mediapipe Face Detection
mp_face_detection = mp.solutions.face_detection
face_detection = mp_face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
# Capture from the default camera
cap = cv2.VideoCapture(0)
# Read one frame
ret, frame = cap.read()
if not ret:
print("Failed to capture an image")
else:
# Convert the frame to RGB (as Mediapipe expects)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the frame
result = face_detection.process(frame_rgb)
# Check if any faces are detected
if result.detections:
print("Faces detected")
for detection in result.detections:
print(detection)
else:
print("No faces detected")
# Release resources
cap.release()
face_detection.close()
mediapipe==0.10.14
opencv-python==4.8.0.76
nuitka==2.4.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment