我用raspbian编写了这个python脚本“ mycv.py”:
void displayMenu();
int multiply(int, int);
void drawRect();
int main()
{
int userChoice = 0;
do
{
displayMenu();
cout << "Enter your choice: ";
cin >> userChoice;
switch (userChoice)
{
// display the area of a rectangle
case 1:
{
int length, width;
cout << "Enter a length: ";
cin >> length;
cout << "Enter a width: ";
cin >> width;
cout << "The area of the rectangle is: " << multiply(length, width) << endl << endl;
drawRect(length, width);
break;
}
}
int multiply(int x, int y)
{
int product = x * y;
return product;
}
void drawRect(int length, int width)
{
// draw the top row
cout << setfill('*') << setw(width) << endl;
// draw the middle rows
// draw the bottom row
cout << setfill('*') << setw(width) << endl;
}
,它将调试并正常运行。然后我用pyinstaller制作可执行文件。 但是在终端中运行文件时。它有错误:
import cv2 as cv
感谢您的帮助
答案 0 :(得分:0)
经过大量调试,我找到了以下解决方案:
获取OpenCV的路径
导入cv2 print(cv2。文件)#/usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.so
在通过pyinstaller进行编译时添加此路径
pyinstaller main.py -n myApp --paths =“ / usr / local / lib / python3.6 / dist-packages / cv2 / python-3.6”
我希望这对其他人也有帮助