完整程序如下:
#include <cstdio>
#include <cv.h>
#include <highgui.h>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
IplImage *frame = NULL;
IplImage *pDstImg = NULL;
CvCapture *capture1 = cvCaptureFromCAM(1);
cvSetCaptureProperty(capture1 , CV_CAP_PROP_FRAME_WIDTH , 320); //寻找膛口质心时获取像素较少的图片
cvSetCaptureProperty(capture1 , CV_CAP_PROP_FRAME_HEIGHT , 240);
char fileName[100];
char key;
int count = 0;
waitKey(3000);
while(1)
{
frame = cvQueryFrame(capture1);
pDstImg = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
/*****添加的程序段:将图像画面旋转180度--仿射变换****/
double angle = 180;
CvPoint2D32f center = cvPoint2D32f(frame->width/2.f,frame->height/2.f);
float m[6];
CvMat map_matrix = cvMat( 2, 3, CV_32F,m);
cv2DRotationMatrix(center,angle,1.0,&map_matrix);
cvWarpAffine (frame, pDstImg, &map_matrix);
cvCopy(pDstImg, frame);
/****到此为止****/
cvFlip(frame, NULL, 1); //水平翻转图像,像照镜子一样,不想要这个效果可以去掉此句
key = cvWaitKey(50);
if(key == 27) break; //按ESC键退出程序
if(key == 'p') //按p键拍照
{
sprintf(fileName, "Picture %d.jpg", ++count); //生成文件名
cvSaveImage(fileName, frame);
cvXorS(frame, cvScalarAll(255), frame); //将拍到的图像反色(闪一下形成拍照效果)
cvShowImage("相机",frame);
cvWaitKey(10); //反色图像显示ms
}
cvShowImage("相机",frame);
// cvShowImage("相机",pDstImg);
}
cvReleaseCapture(&capture1);
return 0;
}
,这个程序之前还能用的,今天运行就出现这个问题了,