//標頭檔>懶得砍掉其他的

#include "stdafx.h"
#include "app2.h"
#include "app2Dlg.h"
#include "afxdialogex.h"
#include "stdafx.h"
#include "afxdialogex.h"
#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <stdio.h>
#include <cxcore.h>
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>






openCV視訊處理

CvCapture *capture;
IplImage *frame;
capture =cvCaptureFromCAM(0) ;
cvNamedWindow("Webcam",0);
while(true)
{
frame = cvQueryFrame(capture);
cvShowImage("Webcam",frame);
if(cvWaitKey(10)>=0)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("Webcam");

 

 


人臉偵測

CvCapture *capture;
IplImage *image_detect;
capture =cvCaptureFromCAM(0) ;
cvNamedWindow("Face Detection Result", 1);
while(true)
{
image_detect = cvQueryFrame(capture);
string cascade_name="haarcascade_frontalface_alt2.xml";
// Load cascade
CvHaarClassifierCascade* classifier=(CvHaarClassifierCascade*)cvLoad(cascade_name.c_str(), 0, 0, 0);
// Quit the application if the input source or the classifier data failed to load properly.
if( !classifier)
{
cerr << "ERROR: Could not load classifier cascade." << endl;

}
// Create a CvMemStorage object for use by the face detection function.
CvMemStorage* facesMemStorage = cvCreateMemStorage(0);

IplImage* tempFrame = cvCreateImage(cvSize(image_detect->width,image_detect->height), IPL_DEPTH_8U, image_detect->nChannels);

// Copy the current frame into the temporary image. Also, make
// sure the images have the same orientation.
if(image_detect->origin == IPL_ORIGIN_TL)
{
cvCopy(image_detect, tempFrame, 0);
}
else
{
cvFlip(image_detect, tempFrame, 0);
}
cvClearMemStorage(facesMemStorage);
CvSeq* faces = cvHaarDetectObjects(tempFrame, classifier, facesMemStorage, 1.1,3, CV_HAAR_DO_CANNY_PRUNING, cvSize(min_face_width, min_face_height));

// If any faces were detected, draw rectangles around them.
if (faces)
{
for(int i = 0; i < faces->total; ++i)
{
// Setup two points that define the extremes of the rectangle,
// then draw it to the image..
CvPoint point1, point2;
CvRect* rectangle = (CvRect*)cvGetSeqElem(faces, i);

point1.x = rectangle->x;
point2.x = rectangle->x + rectangle->width;
point1.y = rectangle->y;
point2.y = rectangle->y + rectangle->height;

cvRectangle(tempFrame, point1, point2, CV_RGB(255,0,0), 3, 8, 0);

//port 發送訊息
DCB dcb;
DWORD byteswritten;
HANDLE hPort = CreateFile( "COM3", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
dcb.BaudRate = CBR_9600; //9600 Baud
dcb.ByteSize = 8; //8 data bits
dcb.Parity = NOPARITY; //no parity
dcb.StopBits = ONESTOPBIT; //1 stop
WriteFile(hPort,"a",1,&byteswritten,NULL);
CloseHandle(hPort); //close the handle
aoe=1;
}
if(aoe==0)
{

//port 發送訊息
DCB dcb;
DWORD byteswritten;
HANDLE hPort = CreateFile( "COM3", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
dcb.BaudRate = CBR_9600; //9600 Baud
dcb.ByteSize = 8; //8 data bits
dcb.Parity = NOPARITY; //no parity
dcb.StopBits = ONESTOPBIT; //1 stop
WriteFile(hPort,"b",1,&byteswritten,NULL);
CloseHandle(hPort); //close the handle
}
aoe=0;
}
///////////////
cvShowImage("Face Detection Result", tempFrame);
if(cvWaitKey(10)>=0)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("Face Detection Result");

///////////////////////////////////////////////////

opencv視訊黑框

主要原因是視訊機的驅動

並不是每個視訊機直接裝上就能用

有些需要重新安裝

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 萌新-工程師 的頭像
    萌新-工程師

    工程師的雜記

    萌新-工程師 發表在 痞客邦 留言(0) 人氣()