1

我正在尝试运行一个使用 samples/python2/facedetect.py 示例的简单 OpenCV python 脚本,但不是循环运行,而是希望它检测面部,然后编写图像。

本质上,我将 cv2.imshow 更改为 cv2.imwrite,它在 Windows 上运行良好。

当我在 Linux (Debian) 上尝试同样的事情时,我得到 Xwindows 错误,例如:

import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9007.
from: can't read /var/mail/video
from: can't read /var/mail/common
./facedetect.py: line 7: syntax error near unexpected token `('
./facedetect.py: line 7: `def detect(img, cascade):'

我不想绘制任何窗口,我想要的只是代码打开一个 jpg,检测面部,然后写一个新的 jpg。OpenCV 是否需要 X 窗口?我浏览了代码,但无法识别需要 X windows 的特定代码行。

4

1 回答 1

2

您刚刚将您的程序作为 shell 的输入。您需要添加一个 hashbang 行,就像#!/usr/bin/python程序文件的第一行一样。或将其调用为python ./facedetect.py

于 2012-05-22T06:09:47.097 回答