I am trying to develop the pong game using python, opencv and mediapipe. The code working in my pc very well, but when i try to take the python file to .exe the exe application throw this error. I am using to convert the python file to exe "pyinstaller" and also used "auto-py-to-exe" both build are not working properly.
моя ошибка:
"cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv- python\opencv\modules\core\src\arithm.cpp:650: ошибка: (-209:размеры входных аргументов не совпадают). Эта операция не является ни «массивом массива» (где массивы имеют одинаковый размер и одинаковое число). каналов), ни «скалярный массив», ни «скалярный массив» в функции «cv::arithm_op»
import cv2
import cvzone
from cvzone.HandTrackingModule import HandDetector
import numpy as np
import time
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
# Importing all images
imgBackground = cv2.imread("Resources/GameScreen.png")
imgGameOver = cv2.imread("Resources/Game Over.png")
imgBall = cv2.imread("Resources/Ball-01.png", cv2.IMREAD_UNCHANGED)
imgBat1 = cv2.imread("Resources/Green Player.png", cv2.IMREAD_UNCHANGED)
imgBat2 = cv2.imread("Resources/Red Player.png", cv2.IMREAD_UNCHANGED)
#imgplayer1Winner = cv2.imread("Resources/Player 1 Win.png")
#imgplayer2Winner = cv2.imread("Resources/Player 2 Win.png")
# = cv2.imread("Resources/Draw-01.png")
# Hand Detector
detector = HandDetector(detectionCon=0.8, maxHands=2)
# Variables
ballPos = [100, 100]
speedX = 15
speedY = 15
gameOver = False
score = [0, 0]
start_time = time.time()
game_duration = 120 # 2 minutes in seconds
while True:
_, img = cap.read()
img = cv2.flip(img, 1)
imgRaw = img.copy()
elapsed_time = time.time() - start_time
remaining_time = max(0, game_duration - int(elapsed_time))
if elapsed_time >= game_duration:
gameOver = True
# Overlay remaining time on top left corner
cv2.putText(img, f"Time: {remaining_time // 60:02}:{remaining_time % 60:02}",
(20, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
# Find the hand and its landmarks
hands, img = detector.findHands(img, flipType=False) # with draw
# Overlaying the background image
print("img shape", img.shape)
print("imgBG", imgBackground.shape)
img = cv2.addWeighted(img, 0.2, imgBackground, 0.8, 0)
# Check for hands
if hands:
for hand in hands:
x, y, w, h = hand['bbox']
h1, w1, _ = imgBat1.shape
y1 = y - h1 // 2
y1 = np.clip(y1, 20, 415)
if hand['type'] == "Left":
img = cvzone.overlayPNG(img, imgBat1, (59, y1))
if 59 < ballPos[0] < 59 + w1 and y1 < ballPos[1] < y1 + h1:
speedX = -speedX
ballPos[0] += 30
#score[0] += 1
if hand['type'] == "Right":
img = cvzone.overlayPNG(img, imgBat2, (1195, y1))
if 1195 - 50 < ballPos[0] < 1195 and y1 < ballPos[1] < y1 + h1:
speedX = -speedX
ballPos[0] -= 30
#score[1] += 1
# Game Over
if ballPos[0] < 40 or ballPos[0] > 1200:
if ballPos[0] > 1200:
score[0] += 1
ballPos = [100, 100]
speedX = 15
speedY = 15
if ballPos[0] < 40:
score[1] += 1
ballPos = [1100, 100] # Reposition the ball closer to Player 2
speedX = -15
speedY = 15
if gameOver:
if score[0] == score[1]:
img = None
imgDraw = cv2.imread("Resources/Draw-01.png")
img = imgDraw
elif score[0] > score[1]:
img = None
imgplayer1Winner = cv2.imread("Resources/Player 1 Win.png")
img = imgplayer1Winner
else:
img = None
imgplayer2Winner = cv2.imread("Resources/Player 2 Win.png")
img = imgplayer2Winner
cv2.putText(img, str(score[0]).zfill(2), (320, 350), cv2.FONT_HERSHEY_COMPLEX, 2.5, (255, 255, 255), 5)
cv2.putText(img, str(score[1]).zfill(2), (870, 350), cv2.FONT_HERSHEY_COMPLEX, 2.5, (255, 255, 255), 5)
#break # End the game
# If game not over move the ball
else:
# Move the Ball
if ballPos[1] >= 500 or ballPos[1]
Подробнее здесь: https://stackoverflow.com/questions/783 ... array-op-a