- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码,它将检测图像中的面部并在面部周围绘制矩形。
CvHaarClassifierCascade *cascade;
CvMemStorage *storage;
void detectFaces (IplImage *newframe);
int key;
int iImg;
int Num_Images=20;
int main( int argc, char** argv )
{
string filename = M:/Trend/FaceDetection/MyCascadeFolder/haarcascade_frontalface_alt2.xml";
storage = cvCreateMemStorage(0) ;
cascade = ( CvHaarClassifierCascade* )cvLoad( filename.c_str());
**//to load a single image**
**IplImage* inImage = cvLoadImage("M:/Trend/FaceDetection775/MyImages/face1.jpg",1);**
//IplImage* inImage = cvLoadImage(argv[1],1); >> It also works fine through command line
detectFaces( inImage );
cvShowImage("FaceDetection2",inImage);
cvSaveImage("M:/FaceDetection/MyImages/OpImages/faces.jpg",inImage);
cvReleaseImage( &inImage);
// **to load no. of images or a complete folder**
char buf[20];
for(iImg=0; iImg<=Num_Images; iImg++)
{
**sprintf(buf, "M:/FaceDetection/ImagesFolder/P%04d.jpg", iImg);**
*// sprintf(buf, argv[2], iImg); // I Tried with this., but its not working*
printf("\n");
inImage = cvLoadImage(buf, CV_LOAD_IMAGE_UNCHANGED);
printf("Input Image = P%04d.jpg\n", iImg);
detectFaces( inImage );
cvShowImage("FaceDetection",inImage);
cvReleaseImage( &inImage );
key= cvWaitKey(0);
if ( key == 'q' || key == 'Q' )
return(0);
}
cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
return 0;
}
**// the actual detectfaces() function goes like this**
void detectFaces( IplImage *newframe)
{
CvSeq *faces = cvHaarDetectObjects( newframe, cascade, storage, 1.15, 5, 0, cvSize( 30, 30 ) );
for( int i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ )
{
CvRect *r = ( CvRect *)cvGetSeqElem( faces, i );
cvRectangle(newframe,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),CV_RGB( 0, 255, 0 ), 2, 8, 0 );
}
}
这里,sprintf() 方法静态拍摄多个图像(在程序本身内)。但我想通过命令行参数将这些多个图像作为单个文件夹传递。
我尝试使用 cvLoadImage() 函数,但它也只需要一张图像作为输入,而不是一个文件夹。
此外,我无法计算它为图像中的每个人脸绘制的矩形数量。,我怎样才能做到这一点......?
请在这方面帮助我。
我正在为我的学者开发人脸检测项目“www.MahdiRezaei.com”,并且我正在使用带有 C、C++ 和 OpenCV 的 Visual Studio-2010。
提前致谢。
最佳答案
您可以更改以下代码以将其与参数一起使用。
#include<Windows.h>
#include<iostream>
#include<opencv2\highgui\highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
WIN32_FIND_DATA data;
HANDLE h = FindFirstFile(L"c:\\Images\\*.*", &data); // first file is the current directory
FindNextFile(h, &data); //second file is the parent directory
vector<Mat> Images;
if (h != INVALID_HANDLE_VALUE)
{
while (FindNextFile(h, &data))
{
string filename = data.cFileName;
sprintf(filename, "%s%s","C:\\Images\\", filename.c_str());
Images.push_back(imread(filename, 1));
delete[] nPtr;
}
}
else
cout << "Error: No such folder." << endl;
FindClose(h);
return 0;
}
关于c - 如何在 OpenCV 中将多个图像作为命令行参数加载到 sprintf() 和 cvLoadImage()...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29225947/
将一些代码从 sprintf 移动到 snprintf -偶然发现了这个奇怪的事件: sprintf(buf+strlen(buf), "ypasZ%c%c", iItem, val); 我不明白那里
在特定 PlayStation 平台附带的 C/C++ 编译器上,我对非标准 ASCII 字符(在翻译语言中使用,例如西类牙语 - 严肃、尖锐,诸如此类)有些困扰 char target_string
有printf。它直接打印到标准输出。 sprintf 怎么样,它的格式和 printf 一样,但是返回一个没有副作用的字符串? 最佳答案 在 Clojure 中,它被称为 format并驻留在 cl
我正在使用字符数组[6];我正在使用 sprintf 将浮点变量转换为字符串,如下所示.. sprintf(array,"%f\0",floatvar); 我正在 LCD 上写入字符数组。 问题是我的
我过去在我的代码中多次使用过这种约定: strcpy ( cTmpA, "hello" ); sprintf ( cTmpA, "%s world", cTmpA ); 最近我将旧的 C 编译器切换到
任何人都可以指出一个源代码文件或一个在 C 中具有良好、可重用的 sprintf() 实现的包,我可以根据自己的需要对其进行自定义吗? 关于我为什么需要它的解释:字符串在我的代码中不是空终止的(二进制
我有一个匹配字符串占位符的数组,如下所示: "some text %s another text %s extra text %s" 和数组: $array[0] match the first %s
我正在尝试实现以下(没有 sprintf 或格式化): void integer_to_string(unsigned int a, char *string) { char arr[
我不明白为什么会这样: Printf.sprintf "%08s" "s" = Printf.sprintf "%8s" "s" - : bool = true 换句话说,我希望: Printf.sp
让我们做一些四舍五入 > round(-0.001, 2) [1] 0 我收到零。 现在结合 sprintf > sprintf("%f", round(-0.001,2)) [1] "-0.0000
我正在尝试以编程方式将字符串宽度值插入 sprintf()格式。 想要的结果是 sprintf("%-20s", "hello") # [1] "hello " 但我想插入
这个问题在这里已经有了答案: How do I use the same parameter more than once? (2 个回答) 5年前关闭。 我使用 sprintf 函数如下: spri
我希望将定义的变量插入到 R 中的字符串中,其中变量将插入多个位置。 我见过sprintf可能有用。 所需输入的示例: a <- "tree" b <- sprintf("The %s is larg
在 中找到的字符串格式化概念sprintf 今天几乎可以在任何语言中找到(你知道,用 %s %d %f 等来扼杀一个字符串,并提供一个变量列表来填充它们的位置)。 哪种语言最初具有提供此功能的库函数或
这是我的代码的一部分 int pic_num = 1; printf("pic_num = %i\n", pic_num); sprintf(picture, "%03d.jpg", pic_num)
为什么会出现这种行为? # Printf.sprintf ("Foo %d %s") 2 "bar";; - : string = "Foo 2 bar" # Printf.sprintf ("Foo
我有这样的SQL查询 if (isset($_POST['no_peserta_mhs_2015'])) { $colname_rec_mhs_2015 = $_POST['no_peserta_mh
我正在尝试使用 F# 交互式控制台打印一个 int。 let x = sprintf "%d", 3 printf x 给出: stdin(12,8): error FS0001: The type
这是一个简单的问题 我需要在 sprintf 函数中复制值 sprintf("%s %s %s",$arg1,$arg1,$arg2); 我怎样才能只传递$arg1一次?似乎无法在 php.net 上
这是一个错误吗? > nchar(sprintf("%-20s", "Sao Paulo")) [1] 20 > nchar(sprintf("%-20s", "São Paulo")) [1] 19
我是一名优秀的程序员,十分优秀!