我正在尝试检测一张脸并在一个单独的文件中记下脸部区域.我该怎么做?我认为我必须使用"faces"(你可以在代码中看到这个var).但是怎么样?
from ffnet import mlgraph, ffnet, tmlgraph, imlgraph
import pylab
import sys
import cv,cv2
import numpy
cascade = cv.Load('C:\opencv\data\haarcascades\haarcascade_frontalface_alt.xml')
def detect(image):
bitmap = cv.fromarray(image)
faces = cv.HaarDetectObjects(bitmap, cascade, cv.CreateMemStorage(0))
if faces:
for (x,y,w,h),n in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,255),3)
return image
if __name__ == "__main__":
cam = cv2.VideoCapture(0)
while 1:
_,frame =cam.read()
frame = numpy.asarray(detect(frame))
cv2.imshow("features", frame)
if cv2.waitKey(1) == 0x1b: # ESC
print 'ESC pressed. Exiting ...'
break
Run Code Online (Sandbox Code Playgroud) 当我启动程序时 - 我收到以下错误:
OpenCV错误:断言失败(scn == 3 || scn == 4)在cv :: cvtColor中,文件C:\ builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\imgproc\src\color.cpp,line 3737
如何删除错误?码:
#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
while …Run Code Online (Sandbox Code Playgroud) 当通过命令行启动我的程序时,有这样的问题:OpenCV错误:图像步骤错误(矩阵不连续,因此其行数不能更改)un cv :: Mat :: reshape,file C:\ builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp,第802行.
程序代码:
#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
while (getline(file, line)) {
stringstream liness(line);
getline(liness, path, …Run Code Online (Sandbox Code Playgroud)