#include "Test_eged.h"
#include <math.h>
IplImage *tempjpg=0,*loadjpg =0,*loadjpg1 =0,*cedge = 0;
IplImage *gray=0,*edge=0;
char EgedName[]="image";
char TackName[]="Threshold";
int edge_width=1;
void OnTacker(int h)
{
cvSmooth(gray,edge,CV_BLUR,3,3,0);
cvNot(gray,edge);
cvCanny(gray,edge,(float)edge_width,(float)edge_width*3,3);
cvZero(cedge);
cvCopy(loadjpg,cedge,edge);
cvShowImage("image",cedge);
}
int main(int argc,char **argv)
{
CWinApp theApp;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
AfxMessageBox("窗口程序初始化出错");
return 1;
}
CString Filter;
CString VideoFileName;
Filter = "(*.jpg)|*.jpg| every files (*.*)|*.*||";
// Filter = "(*.mp4;*.avi)|*.avi;*.mp4|(*.mp4)|*.mp4| every files (*.*)|*.*||";
CFileDialog FileDlg (TRUE, NULL, NULL, OFN_HIDEREADONLY, Filter);
// sprintf(Title,"打开 Cam_%d 视频文件名",Cam_id+1);
FileDlg.m_ofn.lpstrTitle="选择文件";
if (FileDlg.DoModal () == IDOK)
{
VideoFileName = FileDlg.GetPathName();
CString nameExe = FileDlg.GetFileExt();
printf("-----%s------\n",nameExe);
printf(VideoFileName);
}
//if((argc==2)&&(tempjpg=cvLoadImage(argv[1],1))!=0)
// cout<<VideoFileName.GetBuffer(VideoFileName.GetLength())<<endl;
if((tempjpg=cvLoadImage(VideoFileName.GetBuffer(VideoFileName.GetLength()),1))!=0)
{
int temp_width=400;//tempjpg->width-X_start;
int temp_height =400;// tempjpg->height-Y_start;
loadjpg=cvCreateImage(cvSize(400,400),8,3);
loadjpg1 = cvCreateImage(cvSize(temp_width,temp_height),IPL_DEPTH_8U,3);
cvSetImageROI(tempjpg,cvRect(X_start,Y_start,temp_width,temp_height));
cvCopyImage(tempjpg, loadjpg);
cvResetImageROI(tempjpg);
// cvResize(loadjpg1,loadjpg);
// cout<<loadjpg1->width<<" "<<loadjpg1->height<<endl;
cout<<loadjpg->width<<" "<<loadjpg->height<<endl;
// cvNamedWindow("imagesrc",1);
// cvShowImage("imagesrc",loadjpg);
//////////////////////旋转和缩放
IplImage *dst = cvCreateImage(cvSize(400,400),8,3);
/* int delta=1;//旋转值
int angle=0;
int opt=0;//1==旋转加缩放 0=旋转
double factor=0.0;
for (;;)
{
float m[6];
CvMat M = cvMat(2,3,CV_32F,m);
int w=loadjpg->width;
int h=loadjpg->height;
if (opt)//
factor = (cos(angle*CV_PI/180.0)+1.05)*2;
else
factor=1;
m[0]=(float)(factor*cos(-angle*2*CV_PI/180.));
m[1]=(float)(factor*sin(-angle*2*CV_PI/180.));
m[3]=-m[1];
m[4]=m[0];
///将旋转中心移到图片中心
m[2]=w*0.5f;
m[5]=h*0.5f;
cvGetQuadrangleSubPix(loadjpg,dst,&M);
cvNamedWindow("imagedst",1);
cvShowImage("imagedst",dst);
if(cvWaitKey(5)==27)
break;
angle = (int)(angle+delta)%360;
}
cvReleaseImage(&dst);*/
/////////////////////
// float k[9]={ 1.f/16 , 2.f/16, 1.f/16,
// 2.f/16 , 4.f/16, 2.f/16,
// 1.f/16 , 2.f/16, 1.f/16};
// CvMat km=cvMat(3,3,CV_32F,k);
// IplConvKernel *elem=cvCreateStructuringElementEx(3,3,1,1,CV_SHAPE_RECT,NULL);
//
// // cvDilate(loadjpg,loadjpg,NULL,1);
// // cvErode(loadjpg,loadjpg,NULL,1);
// cvFilter2D(loadjpg,loadjpg,&km,cvPoint(-1,-1));
// cvReleaseStructuringElement(&elem);
// cvCopyMakeBorder(loadjpg,loadjpg,cvPoint(0,0),IPL_BORDER_CONSTANT,cvScalar(255,0,0,0));
// //
// // cvApproxChains()
// cvNamedWindow("imagedst",1);
// cvShowImage("imagedst",loadjpg);
// if(cvWaitKey(5)==27)
// break;
//CvArr()
// cvWaitKey(0);
////for-loop
///////////////////////
// IplImage *temp_dst=cvCreateImage(cvSize(256,256),8,3);
IplImage *temp_dst=cvCreateImage(cvGetSize(loadjpg),8,3);
IplImage *temp_src=cvCreateImage(cvGetSize(loadjpg),8,3);
// cvErode(loadjpg,temp_dst,NULL,1);
// cvDilate(temp_dst,temp_src,NULL,1);
// cvLogPolar(tempjpg,temp_dst,cvPoint2D32f(tempjpg->width/2,tempjpg->height/2),40,
// CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
// cvLogPolar(temp_dst,temp_src,cvPoint2D32f(tempjpg->width/2,tempjpg->height/2),40,
// CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP);
// cvNamedWindow("temp_dst",1);
// cvShowImage("temp_dst",temp_dst);
// cvNamedWindow("temp_src",1);
// cvShowImage("temp_src",temp_src);
// cvWaitKey(0);
int width = loadjpg->width;
int height = loadjpg->height;
cedge = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
gray = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
edge = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
/////////////////////////
cvCvtColor(loadjpg,gray,CV_BGRA2GRAY);
cvNamedWindow("image",1);
cvShowImage("image",loadjpg1);
cvCreateTrackbar("love","image",&edge_width,100,OnTacker);
OnTacker(0);
cvWaitKey(0);
cvReleaseImage(&loadjpg);
cvReleaseImage(&gray);
cvReleaseImage(&edge);
cvReleaseImage(&tempjpg);
cvDestroyWindow("image");
cvDestroyWindow("imagesrc");
return 1;
}
return 1;
}