/*
#include <cv.h>
#include <highgui.h>
#include <fstream>
#include <string.h>
#include <Windows.h>
HANDLE hMutex;
using namespace std;
using namespace cv;
void cal_cubesnumber(int xx);
void cal_cubesnumber1(int xx1);
void cal_cubesnumber2(int xx2);
void cal_cubesnumber3(int xx3);
int Pixel[2000][2000]={1};
int Pixel1[2000][2000]={1};
int Pixel2[2000][2000]={1};
int Pixel3[2000][2000]={1};
int Tongji[40][2]={0};
int Tongji1[40][2]={0};
int Tongji2[40][2]={0};
int Tongji3[40][2]={0};
DWORD WINAPI PROCESS1(LPVOID lpParameter)
{
WaitForSingleObject(hMutex,INFINITE);
IplImage *canny = NULL;
IplImage *sr = NULL;
double low_thresh=40.0;
double hig_thresh=200.0;
char name1[10];
for(int i=11;i<21;i++)
{
sprintf(name1,"%d.jpg",i);
string fname1=name1;
sr=cvLoadImage(fname1.c_str());
if(sr!=0)
{
canny=cvCreateImage(cvGetSize(sr),IPL_DEPTH_8U,1);
cvCanny(sr,canny,low_thresh,hig_thresh,3);
cvSaveImage("Canny1.jpg",canny);
cal_cubesnumber1(i);
}
}
cvReleaseImage(&sr);
cvReleaseImage(&canny);
ReleaseMutex(hMutex);
return 0;
}
DWORD WINAPI PROCESS2(LPVOID lpParameter)
{
WaitForSingleObject(hMutex,INFINITE);
IplImage *canny = NULL;
IplImage *sr = NULL;
double low_thresh=40.0;
double hig_thresh=200.0;
char name2[10];
for(int i=21;i<31;i++)
{
sprintf(name2,"%d.jpg",i);
string fname2=name2;
sr=cvLoadImage(fname2.c_str());
if(sr!=0)
{
canny=cvCreateImage(cvGetSize(sr),IPL_DEPTH_8U,1);
cvCanny(sr,canny,low_thresh,hig_thresh,3);
cvSaveImage("Canny2.jpg",canny);
cal_cubesnumber2(i);
}
}
cvReleaseImage(&sr);
cvReleaseImage(&canny);
ReleaseMutex(hMutex);
return 0;
}
DWORD WINAPI PROCESS3(LPVOID lpParameter)
{
WaitForSingleObject(hMutex,INFINITE);
IplImage *canny = NULL;
IplImage *sr = NULL;
double low_thresh=40.0;
double hig_thresh=200.0;
char name3[10];
for(int i=31;i<41;i++)
{
sprintf(name3,"%d.jpg",i);
string fname3=name3;
sr=cvLoadImage(fname3.c_str());
if(sr!=0)
{
canny=cvCreateImage(cvGetSize(sr),IPL_DEPTH_8U,1);
cvCanny(sr,canny,low_thresh,hig_thresh,3);
cvSaveImage("Canny3.jpg",canny);
cal_cubesnumber3(i);
}
}
cvReleaseImage(&sr);
cvReleaseImage(&canny);
ReleaseMutex(hMutex);
return 0;
}
void main()
{
int start,end;
start=clock();
char name[10];
HANDLE pThread1=CreateThread(NULL,0,PROCESS1,NULL,0,NULL);
HANDLE pThread2=CreateThread(NULL,0,PROCESS2,NULL,0,NULL);
HANDLE pThread3=CreateThread(NULL,0,PROCESS3,NULL,0,NULL);
HANDLE hMutex=CreateMutex(NULL,FALSE,NULL);
CloseHandle(pThread1);
CloseHandle(pThread2);
CloseHandle(pThread3);
WaitForSingleObject(hMutex,INFINITE);
IplImage *canny = NULL;
IplImage *sr = NULL;
double low_thresh=40.0;
double hig_thresh=200.0;
for(int i=1;i<11;i++)
{
sprintf(name,"%d.jpg",i);
string fname=name;
sr=cvLoadImage(fname.c_str());
if(sr!=0)
{
canny=cvCreateImage(cvGetSize(sr),IPL_DEPTH_8U,1);
cvCanny(sr,canny,low_thresh,hig_thresh,3);
cvSaveImage("Canny.jpg",canny);
cal_cubesnumber(i);
}
}
cvReleaseImage(&sr);
cvReleaseImage(&canny);
ReleaseMutex(hMutex);
end=clock();
double totaltime=(double)(end-start)/CLOCKS_PER_SEC;
cout<<totaltime<<"\n";
remove("Canny.jpg");
remove("Canny1.jpg");
remove("Canny2.jpg");
remove("Canny3.jpg");
getchar();
}
void cal_cubesnumber(int xx)
{
int Tongji[40][2]={0};
IplImage *m=cvLoadImage("Canny.jpg",1);
int height=(*m).height;
int width=(*m).width;
CvSize zz;
zz.height=height;
zz.width=width;
IplImage *m1;
m1=cvCreateImage(zz,IPL_DEPTH_8U,1);
cvCvtColor(m,m1,CV_BGR2GRAY);
for(int x=0;x<height;x++)
{
uchar *ptr=(uchar *)m1->imageData+x*m1->widthStep;
for(int y=0;y<width;y++)
{
int intensity=ptr[y];
if(intensity>200)
{
Pixel[y][x]=0;
}
else
{
Pixel[y][x]=1;
}
}
}
for(int a=4;a<(*m1).width-4;a++)
for(int bc=3;bc<33;bc++)
{
for(int b=4;b<(*m1).height-4;b++)
{
if( Pixel[a][b]==0&&Pixel[a][b+1]==0
&&Pixel[a+bc-2][b-1]==0&&Pixel[a+bc-1][b-1]==0
&&Pixel[a+1][b+bc-2]==0&&Pixel[a+2][b+bc-2]==0
&&Pixel[a+bc-1][b+bc-3]==0&&Pixel[a+bc-1][b+bc-4]==0
) //正方形判断
{
Tongji[bc][0]=bc;
Tongji[bc][1]++;
Pixel[a][b]=1;
}
}
if(Tongji[bc][1]>=5)
{
cout<<xx<<"帧有马赛克。\n";//<<endl;
goto A;
}
}
A: cvReleaseImage(&m);
cvReleaseImage(&m1);
}
void cal_cubesnumber1(int xx1)
{
int Tongji1[40][2]={0};
IplImage *m=cvLoadImage("Canny1.jpg",1);
int height=(*m).height;
int width=(*m).width;
CvSize zz;
zz.height=height;
zz.width=width;
IplImage *m1;
m1=cvCreateImage(zz,IPL_DEPTH_8U,1);
cvCvtColor(m,m1,CV_BGR2GRAY);
for(int x=0;x<height;x++)
{
uchar *ptr=(uchar *)m1->imageData+x*m1->widthStep;
for(int y=0;y<width;y++)
{
int intensity=ptr[y];
if(intensity>200)
{
Pixel1[y][x]=0;
}
else
{
Pixel1[y][x]=1;
}
}
}
for(int a=4;a<(*m1).width-4;a++)
for(int bc=3;bc<33;bc++)
{
for(int b=4;b<(*m1).height-4;b++)
{
if( Pixel1[a][b]==0&&Pixel1[a][b+1]==0
&&Pixel1[a+bc-2][b-1]==0&&Pixel1[a+bc-1][b-1]==0
&&Pixel1[a+1][b+bc-2]==0&&Pixel1[a+2][b+bc-2]==0
&&Pixel1[a+bc-1][b+bc-3]==0&&Pixel1[a+bc-1][b+bc-4]==0
) //正方形判断
{
Tongji1[bc][0]=bc;
Tongji1[bc][1]++;
Pixel1[a][b]=1;
}
}
if(Tongji1[bc][1]>=5)
{
cout<<xx1<<"帧有马赛克。\n";//<<endl;
goto B;
}
}
B: cvReleaseImage(&m);
cvReleaseImage(&m1);
}
void cal_cubesnumber3(int xx3)
{
int Tongji2[40][2]={0};
IplImage *m=cvLoadImage("Canny3.jpg",1);
int height=(*m).height;
int width=(*m).width;
CvSize zz;
zz.height=height;
zz.width=width;
IplImage *m1;
m1=cvCreateImage(zz,IPL_DEPTH_8U,1);
cvCvtColor(m,m1,CV_BGR2GRAY);
for(int x=0;x<height;x++)
{
uchar *ptr=(uchar *)m1->imageData+x*m1->widthStep;
for(int y=0;y<width;y++)
{
int intensity=ptr[y];
if(intensity>200)
{
Pixel2[y][x]=0;
}
else
{
Pixel2[y][x]=1;
}
}
}
for(int a=4;a<(*m1).width-4;a++)
for(int bc=3;bc<33;bc++)
{
for(int b=4;b<(*m1).height-4;b++)
{
if( Pixel2[a][b]==0&&Pixel2[a][b+1]==0
&&Pixel2[a+bc-2][b-1]==0&&Pixel2[a+bc-1][b-1]==0
&&Pixel2[a+1][b+bc-2]==0&&Pixel2[a+2][b+bc-2]==0
&&Pixel2[a+bc-1][b+bc-3]==0&&Pixel2[a+bc-1][b+bc-4]==0
) //正方形判断
{
Tongji2[bc][0]=bc;
Tongji2[bc][1]++;
Pixel2[a][b]=1;
}
}
if(Tongji2[bc][1]>=5)
{
cout<<xx3<<"帧有马赛克。\n";//<<endl;
goto C;
}
}
C: cvReleaseImage(&m);
cvReleaseImage(&m1);
}
void cal_cubesnumber2(int xx2)
{
int Tongji3[40][2]={0};
IplImage *m=cvLoadImage("Canny2.jpg",1);
int height=(*m).height;
int width=(*m).width;
CvSize zz;
zz.height=height;
zz.width=width;
IplImage *m1;
m1=cvCreateImage(zz,IPL_DEPTH_8U,1);
cvCvtColor(m,m1,CV_BGR2GRAY);
for(int x=0;x<height;x++)
{
uchar *ptr=(uchar *)m1->imageData+x*m1->widthStep;
for(int y=0;y<width;y++)
{
int intensity=ptr[y];
if(intensity>200)
{
Pixel3[y][x]=0;
}
else
{
Pixel3[y][x]=1;
}
}
}
for(int a=4;a<(*m1).width-4;a++)
for(int bc=3;bc<33;bc++)
{
for(int b=4;b<(*m1).height-4;b++)
{
if( Pixel3[a][b]==0&&Pixel3[a][b+1]==0
&&Pixel3[a+bc-2][b-1]==0&&Pixel3[a+bc-1][b-1]==0
&&Pixel3[a+1][b+bc-2]==0&&Pixel3[a+2][b+bc-2]==0
&&Pixel3[a+bc-1][b+bc-3]==0&&Pixel3[a+bc-1][b+bc-4]==0
) //正方形判断
{
Tongji3[bc][0]=bc;
Tongji3[bc][1]++;
- 1
- 2
- 3
前往页