这个代码块(在views.py中)由URL触发.导入cv2时没有问题.(使用virtualenvwrapper尝试的同样的事情显示相同的结果(添加所有必需的库之后)相机初始化和....
def caminit(request):
cam.open(0)
img=cam.read()
cv2.imwrite("snap"+".jpg",img[1])
cam.release() #takes the instant pic
faceCascade =cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
Run Code Online (Sandbox Code Playgroud)
检查时 print type(faceCascade) 给出<type 'cv2.CascadeClassifier'>.对象已创建.
继续前进 caminit
image = cv2.imread("snap.jpg")
# when checked with image.dtype it shows correct uint8 also image.shape shows correct data {Eg: (480, 640, 3)}
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
Run Code Online (Sandbox Code Playgroud)
现在关键部分"寻找面孔的数量"
print "Found {0} faces!".format(len(faces))
Run Code Online (Sandbox Code Playgroud)
终端输出:
Found 0 faces!
Run Code Online (Sandbox Code Playgroud)
为什么会这样? …
以下给出了下面提到的代码的错误.哪里出错了?
error: ‘function’ is not a member of ‘std’
Run Code Online (Sandbox Code Playgroud)
我想使用C++ std lib队列进行优先级队列,最小化队列是IceCream,它花费的时间最少.我试过实现这个 - > 用自定义比较器在c ++中声明一个priority_queue
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <iterator>
#include <string>
#include <sstream>
using namespace std;
class IceCream
{
public:
int time_to_prep;
IceCream(int flav) {
time_to_prep = flav;
}
};
bool Compare(IceCream a, IceCream b)
{
return a.time_to_prep > b.time_to_prep;
}
int main()
{
priority_queue<IceCream, vector<IceCream>, std::function<bool(IceCream a, IceCream b)> > my_pq(Compare);
my_pq.push(IceCream(4)); …Run Code Online (Sandbox Code Playgroud)