WSADATA wsaData = {0};
SOCKET socksvr;
int iPort=7900;
//服务器地址长度
int iLen = 0;
//接收数据的缓冲
int iSend = 0;
int iRecv = 0;
if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0)
{
printf("Failed to load Winsock.\n");
return 0;
}
struct sockaddr_in ser;
ser.sin_family=AF_INET;
ser.sin_port=htons(8299);
ser.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
//建立服务端数据报套接口
socksvr=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
//udp绑定
bind(socksvr,(struct sockaddr*)&ser,sizeof(ser));
//客户端信息地址,这里是点对点通信,需要加上IP+port。
//对于UDP来说,可以不用IP,因为它是无连接的。只要在一个网段就行。
//也就是说,无论是TCP还是UDP,都可以指定向某个电脑的端口发送数据。
//只需要在客户端监听此端口就行。对于TCP:connect,对于UDP:listen
struct sockaddr_in clientaddr = {0};
clientaddr.sin_family=AF_INET;
clientaddr.sin_port=htons(8300);//7901
clientaddr.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
int nLen = sizeof(clientaddr);
Sleep(10);
string cam_dir = "C:\\CameraData";
mkdir(cam_dir.c_str());
while(1)
{
matrix.Num = 0;
matrix_vehicle.Num = 0;
if (0)//imgs_lane.isNew || imgs_pedestrain.isNew || imgs_vehicle.isNew
{
matrix = imgs_lane.Get();
pe = imgs_pedestrain.Get();
matrix_vehicle = imgs_vehicle.Get();
//行人有宽度信息,所以需要增加的不止一个点
matrix.point[matrix.Num++] = pe;//增加行人,若没有,其标志位为0
if (matrix_vehicle.Num > 1) //增加车辆,若没有,其标志位为0
{
for (int i = 0; i < matrix_vehicle.Num; ++i)
{
matrix.point[matrix.Num++] = matrix_vehicle.point[i];
}
}
if(matrix.Num > 0)
{
int ret = sendzmq->PubMsg("Camera_Data",matrix);
//int len = matrix.Num*sizeof(Point) + 4;
//sendudp->udpSendToCanet((unsigned char*)&matrix,len);
//cout << "ret num: " << ret << endl;
}
}
IplImage* demo = imgs_gray.Get();
//存储图片
//数据独立存储
char szFileName[_MAX_PATH] = {0};
SYSTEMTIME sys;
GetLocalTime(&sys);
long cntTime = sys.wHour*60*60*1000 + sys.wMinute*60*1000 +
sys.wSecond*1000 + sys.wMilliseconds;
sprintf(szFileName, "%ld",cntTime);
string dir = cam_dir + "\\";
string tenp = "";
tenp = szFileName;
tenp += ".jpg";
dir += tenp;
//cvSaveImage 第三个参数可以设置压缩的质量
int
params[3];
params[0] = CV_IMWRITE_JPEG_QUALITY;
params[1] = 85;
params[2] = 0;
cvSaveImage(dir.c_str(),demo,params);
Sleep(1);
iSend=sendto(socksvr,dir.c_str(),dir.size(),0,(struct sockaddr*)&clientaddr,nLen);
cout << "ret: " << iSend << endl;
Sleep(100);
}
return 0;
}