test2eyesDlg.cpp
上传用户:lwxipeng
上传日期:2022-05-16
资源大小:15982k
文件大小:25k
- // test2eyesDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "test2eyes.h"
- #include "test2eyesDlg.h"
- //---OpenCV的库文件-----------
- #pragma comment (lib,"cv200d")
- #pragma comment (lib,"highgui200d")
- #pragma comment (lib, "cxcore200d")
- //---gsl的库文件-----------
- #pragma comment (lib, "libgsl.a")
- #include "sift.h"
- #include "imgfeatures.h"
- #include "kdtree.h"
- #include "utils.h"
- #include "xform.h"
- #include <Windows.h>
- #include <cv.h>
- #include <cxcore.h>
- #include <highgui.h>
- #include <stdio.h>
- #include <math.h>
- // #include <mmsystem.h>
- // #pragma comment(lib, "WINMM.LIB")
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // Ctest2eyesDlg 对话框
- #define MYTIMER 3
- Ctest2eyesDlg::Ctest2eyesDlg(CWnd* pParent /*=NULL*/)
- : CDialog(Ctest2eyesDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- Ctest2eyesDlg::~Ctest2eyesDlg()
- {
- m_ThreadExit = TRUE;
- //------释放内存存储器-----------
- cvReleaseImage( &stacked );
- cvReleaseImage( &img1 );
- cvReleaseImage( &img2 );
- kdtree_release( kd_root );
- free( feat1 );
- free( feat2 );
- }
- void Ctest2eyesDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_SLIDER1, m_slider);
- }
- BEGIN_MESSAGE_MAP(Ctest2eyesDlg, CDialog)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDOK, &Ctest2eyesDlg::OnBnClickedOk)
- ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, &Ctest2eyesDlg::OnNMReleasedcaptureSlider1)
- ON_WM_TIMER()
- ON_WM_CTLCOLOR()
- ON_BN_CLICKED(IDCANCEL, &Ctest2eyesDlg::OnBnClickedCancel)
- END_MESSAGE_MAP()
- // Ctest2eyesDlg 消息处理程序
- BOOL Ctest2eyesDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- CString strsj;
- m_sj = (CEdit*)this->GetDlgItem( IDC_EDIT_SJ );
- strsj= _T("70");
- m_sj->SetWindowText( strsj);
- CString strjj;
- m_jj = (CEdit*)this->GetDlgItem( IDC_EDIT_JJ );
- strjj= _T("370");
- m_jj->SetWindowText( strjj);
- CString strmin;
- m_min = (CEdit*)this->GetDlgItem( IDC_EDIT_MIN );
- strmin= _T("20");
- m_min->SetWindowText( strmin);
- CString strmax;
- m_max = (CEdit*)this->GetDlgItem( IDC_EDIT_MAX );
- strmax= _T("1000");
- m_max->SetWindowText( strmax);
- m_slider.SetRange(1,30,TRUE);
- m_slider.SetPos(3);
- CString m_LIP,m_RIP;
- m_LIP= _T("192.168.10.46");
- m_RIP= _T("192.168.10.47");
- m_RightReceived = FALSE;
- m_LeftReceived= FALSE;
- m_processing= FALSE;
- m_ThreadExit = TRUE;
- m_lip = (CEdit*)this->GetDlgItem( IDC_EDIT_L );
- m_rip = (CEdit*)this->GetDlgItem( IDC_EDIT_R );
- m_lip->SetWindowText( m_LIP);
- m_rip->SetWindowText( m_RIP);
- m_pos = 5;
- stacked = NULL;
- memset(m_ju,0,sizeof(struct des)*1000);
- memset(m_out_ju,0,sizeof(struct des)*1000);
- m_ju_k = 0;
- m_yu_zhi_enable =FALSE;
- // TODO: 在此添加额外的初始化代码
- m_BMPDisplayBrush.DeleteObject();
- m_BMPDisplayBrush.CreateSolidBrush(RGB(255,255,255));
- m_BMP_OK.LoadBitmap(IDB_BITMAP_OK);
- m_BMP_NG.LoadBitmap(IDB_BITMAP_NG);
- m_BMP_WAIT.LoadBitmap(IDB_BITMAP_WAIT);
- GetDlgItem(IDC_STATIC_ICON)->MoveWindow(10,10,50,50);
- GetDlgItem(IDC_STATIC_ICON)->GetWindowRect(m_BMPDisplayRect);
- ScreenToClient(m_BMPDisplayRect);
- ShowICON(0);
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void Ctest2eyesDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- void Ctest2eyesDlg::ShowICON(int nicon)
- {
- if (nicon == 0)
- {
- m_BMPDisplayBrush.DeleteObject();
- m_BMPDisplayBrush.CreatePatternBrush(&m_BMP_WAIT);
- InvalidateRect(m_BMPDisplayRect,FALSE);
- }
- if (nicon == 1)
- {
- m_BMPDisplayBrush.DeleteObject();
- m_BMPDisplayBrush.CreatePatternBrush(&m_BMP_OK);
- InvalidateRect(m_BMPDisplayRect,FALSE);
- }
- if (nicon == 2)
- {
- m_BMPDisplayBrush.DeleteObject();
- m_BMPDisplayBrush.CreatePatternBrush(&m_BMP_NG);
- InvalidateRect(m_BMPDisplayRect,FALSE);
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- //
- HCURSOR Ctest2eyesDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void Ctest2eyesDlg::OnBnClickedOk()
- {
- m_ThreadExit = FALSE;
- AfxBeginThread( ThreadL , this );
- AfxBeginThread( ThreadR , this );
- SetTimer( MYTIMER , 500 , NULL );
- }
- void Ctest2eyesDlg::test_SIFT()
- {
- // if (m_RightReceived == FALSE || m_LeftReceived == FALSE )
- // {
- // return ;
- // }
- m_processing = TRUE;
- TRACE(_T("Processing One...rn"));
- ShowICON(0);
- int l=0;
- if(l<5)
- l=4;
- char img1_file[] = "D:\project\pic\001.jpg";
- char img2_file[] = "D:\project\pic\002.jpg" ;
- double imgzoom_scale=1.0;
- struct feature* feat;
- struct feature** nbrs;
- CvPoint pt1 ={0,0}, pt2={0,0};
- double d0, d1;
- int n1, n2, k, i;
- static int m = 0;
- //cvReleaseImage(&img1);
- img1 = cvLoadImage( img1_file, 1 );
- if( ! img1 )
- {
- //fatal_error( "unable to load image from %s", img1_file );
- CString strerr;
- strerr.Format(_T("unable to load image from img1.rn"));
- TRACE(strerr);
- }
-
- //cvReleaseImage(&img2);
- img2 = cvLoadImage( img2_file, 1 );
- if( ! img2 )
- {
- CString strerr;
- strerr.Format(_T("unable to load image from img2.rn"));
- TRACE(strerr);
- }
-
- stacked = stack_imgs( img1, img2 );
- n1 = sift_features( img1, &feat1 );
- n2 = sift_features( img2, &feat2 );
- kd_root = kdtree_build( feat2, n2 );
- m_ju_k = 0;
- for( i = 0; i < n1; i++ )
- {
- feat = feat1 + i;
- k = kdtree_bbf_knn( kd_root, feat, 2, &nbrs, KDTREE_BBF_MAX_NN_CHKS );
- if( k == 2 )
- {
- d0 = descr_dist_sq( feat, nbrs[0] );
- d1 = descr_dist_sq( feat, nbrs[1] );
- if( d0 < d1 * NN_SQ_DIST_RATIO_THR )
- {
- pt1 = cvPoint( cvRound( feat->x ), cvRound( feat->y ) );
- pt2 = cvPoint( cvRound( nbrs[0]->x ), cvRound( nbrs[0]->y ) );
- //---------存储单个点坐标到点序列中----------
- pt2.x += img1->width + 20;
- m_ju[m_ju_k].y = abs(pt1.y - pt2.y);
- m_ju[m_ju_k].lx = pt1.x;
- m_ju[m_ju_k].ly = pt1.y;
- m_ju[m_ju_k].rx = pt2.x;
- m_ju[m_ju_k].ry = pt2.y;
- m_ju[m_ju_k].x = abs(pt2.x - pt1.x - img1->width - 20);
- m_ju[m_ju_k].s = m_ju[m_ju_k].x;
- CString str1;
- m_sj->GetWindowText(str1);
- ULONG sj;
- sj = _ttoi(str1.GetBuffer());;
- CString str2;
- m_jj->GetWindowText(str2);
- ULONG jj;
- jj = _ttoi(str2.GetBuffer());
- if ( jj != 0 && sj != 0)
- {
- int z;
- z=jj*sj;
- if (m_ju[m_ju_k].s!=0)
- {
- m_ju[m_ju_k].L_des = z/m_ju[m_ju_k].s;
- }
- m_ju_k++;
- }
- }
- }
- free( nbrs );
- }
- m_yu_zhi_enable =TRUE;
- Yu_Zhi();
- TRACE(_T("Processing One OK.rn"));
- return ;
-
- }
- void Ctest2eyesDlg::Yu_Zhi()
- {
- TRACE(_T("Processing Two.rn"));
- if (m_yu_zhi_enable == TRUE)
- {
- BOOL findsth = FALSE;
- for (int dota = 0;dota < m_ju_k; dota++)
- {
- CString str_min,str_max;
- m_max->GetWindowText(str_max);
- m_min->GetWindowText(str_min);
- ULONG mmax,mmin;
- mmax = _ttoi(str_max.GetBuffer());
- mmin = _ttoi(str_min.GetBuffer());
- if ((m_ju[dota].L_des>mmin) && (m_ju[dota].L_des<mmax) && (m_ju[dota].y<7))
- {
- findsth =TRUE;
- // PlaySound(__T("D:\dfa.wma"),NULL,SND_ASYNC|SND_LOOP);
- TRACE(_T("imag1 cood:%3d,%3drn"),m_ju[dota].lx,m_ju[dota].ly);
- TRACE(_T("imag2 cood:%3d,%3drn"),m_ju[dota].rx,m_ju[dota].ry);
- TRACE(_T("destence:%5drn"),m_ju[dota].L_des);
- cvRectangle(stacked,cvPoint(m_ju[dota].lx - m_ju[dota].s/m_pos,m_ju[dota].ly - m_ju[dota].s/m_pos),cvPoint(m_ju[dota].lx + m_ju[dota].s/m_pos,m_ju[dota].ly + m_ju[dota].s/m_pos),CV_RGB(255,0,0),1,8,0);
- cvRectangle(stacked,cvPoint(m_ju[dota].rx - m_ju[dota].s/m_pos,m_ju[dota].ry - m_ju[dota].s/m_pos),cvPoint(m_ju[dota].rx + m_ju[dota].s/m_pos,m_ju[dota].ry + m_ju[dota].s/m_pos),CV_RGB(255,0,0),1,8,0);
- dota++;
- }
- }
- if (findsth)
- {
- ShowICON(2);
- }
- else
- {
- ShowICON(1);
- }
- cvDestroyAllWindows;
- cvNamedWindow( "img_feature", 1 );
- cvShowImage( "img_feature", stacked );
- cvReleaseImage( &stacked );
- cvReleaseImage( &img1 );
- cvReleaseImage( &img2 );
- kdtree_release( kd_root );
- free( feat1 );
- free( feat2 );
- m_RightReceived = FALSE;
- m_LeftReceived = FALSE;
- m_processing = FALSE;
- TRACE(_T("Processing Two OK.rn"));
- }
- m_yu_zhi_enable = FALSE;
- }
- void Ctest2eyesDlg::OnNMReleasedcaptureSlider1(NMHDR *pNMHDR, LRESULT *pResult)
- {
- m_pos=m_slider.GetPos();
- Yu_Zhi();
- *pResult = 0;
- }
- UINT ThreadR( LPVOID g)
- {
- WSADATA wsa;
- /* initialize socket */
- WSAStartup(MAKEWORD(1,1),&wsa);
- Ctest2eyesDlg * thisClass = (Ctest2eyesDlg*)g;
- SOCKET m_serverSocket;
- /* create socket */
- m_serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- SOCKADDR_IN serverAddr;
- ZeroMemory((char *)&serverAddr,sizeof(serverAddr));
- serverAddr.sin_family = AF_INET;
- serverAddr.sin_port = htons(5565);
- serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- /* bind socket */
- bind(m_serverSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
- struct sockaddr_in daddr;
- memset((void *)&daddr,0,sizeof(daddr));
- daddr.sin_family=AF_INET;
- daddr.sin_port=htons(80);
- CString str1 ;
- thisClass->m_rip->GetWindowText(str1);
- char rip[40];
- wcstombs(rip , str1.GetBuffer() , 39 );
- daddr.sin_addr.s_addr=inet_addr(rip);
- int error = connect(m_serverSocket,(struct sockaddr *)&daddr,sizeof(daddr));
- const char * buf = "GET /MJPEG.CGI HTTP/1.0rnrn";
- fd_set fdRead; /* Read concourse define. */
- int ret; /* Return value. */
- TIMEVAL aTime; /* Event wait time define. */
- char recvBuf[RECV_BUF_SIZE];
- int allcount = 0;
- aTime.tv_sec = 1;
- aTime.tv_usec = 0;
- int recvLen;
- int f_recv = F_RECEIVE_NOWORKR;
- send( m_serverSocket,buf,100,0);
- TRACE(__T("Right Socket ok.rn"));
- while (thisClass->m_ThreadExit == FALSE)
- {
- if (thisClass->m_RightReceived == TRUE)
- {
- TRACE(__T("Right Wait for Processing.rn"));
- Sleep(10);
- continue;
- }
- TRACE(__T("Right Receiving.rn"));
- /* Set empty to the fdRead Event. */
- FD_ZERO(&fdRead);
- /* Set read event to the client socket. */
- FD_SET(m_serverSocket,&fdRead);
- /* To judge whether there is any read event. */
- ret = select(0,&fdRead,NULL,NULL,&aTime);
- if (ret > 0)
- {
- if (FD_ISSET(m_serverSocket,&fdRead))
- {
- /* read event happen */
- recvLen = 0;
- /* recieve data */
- memset( recvBuf , 0 , RECV_BUF_SIZE );
- recvLen = recv( m_serverSocket , recvBuf , RECV_BUF_SIZE , 0 );
- if( recvLen <= 0 )
- {
- TRACE( _T( "Right TCP recive nothing.rn" ) );
- continue;
- }
- if( F_RECEIVE_NOWORKR == f_recv )
- {
- int tempcount;
- for( tempcount = 0 ; tempcount < recvLen - 1 ; tempcount++ )
- {
- if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- {
- f_recv = F_RECEIVE_BEGINR;
- break;
- }
- }
- if( F_RECEIVE_BEGINR == f_recv )
- {
- f_recv = F_RECEIVE_R;
- thisClass->recvBytePointerR = 0;
- memcpy( thisClass->recvImageBufR , recvBuf + tempcount , recvLen - tempcount );
- thisClass->recvBytePointerR = recvLen - tempcount;
- }
- }
- else if( F_RECEIVE_R == f_recv )
- {
- int tempcount;
- for( tempcount = 0 ; tempcount < recvLen ; tempcount++ )
- {
- if( ( recvBuf[tempcount - 2] == (char)0xFF ) && ( recvBuf[tempcount - 1] == (char)0xD9 ) )
- {
- f_recv = F_RECEIVE_OVERR;
- break;
- }
- }
- if( F_RECEIVE_R == f_recv ) /* 未接收完一个文件 */
- {
- memcpy( thisClass->recvImageBufR + thisClass->recvBytePointerR , recvBuf , recvLen );
- thisClass->recvBytePointerR += recvLen;
- }
- else if( F_RECEIVE_OVERR == f_recv ) /* 接收完一个文件 */
- {
- memcpy( thisClass->recvImageBufR + thisClass->recvBytePointerR , recvBuf , tempcount );
- thisClass->recvBytePointerR += tempcount;
- CString strL;
- strL.Format( __T("D:\project\pic\001.jpg") , 1 );
- TRACE(__T("Right Received file.rn"));
- CFile ka;
- if( ka.Open( strL , CFile::modeCreate | CFile::modeReadWrite ) == TRUE )
- {
- TRACE(__T("Right Writting file.rn"));
- ka.SeekToBegin();
- ka.Write( thisClass->recvImageBufR , thisClass->recvBytePointerR );
- ka.Close();
- thisClass->m_RightReceived = TRUE;
- }
- TRACE(__T("Right Received done.rn"));
- if( thisClass->f_MutexImageBufR == MUTEX_NONUSE )
- {
- thisClass->f_MutexImageBufR = MUTEX_USE;
- memcpy(thisClass->imageBufR.buf , thisClass->recvImageBufR , thisClass->recvBytePointerR );
- thisClass->imageBufR.size = thisClass->recvBytePointerR;
- thisClass->f_MutexImageBufR = MUTEX_NONUSE;
- }
- f_recv = F_RECEIVE_NOWORKR;
- for( ; tempcount < recvLen - 1 ; tempcount++ )
- {
- if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- {
- f_recv = F_RECEIVE_BEGINR;
- break;
- }
- }
- if( F_RECEIVE_BEGINR == f_recv )
- {
- f_recv = F_RECEIVE_R;
- thisClass->recvBytePointerR = 0;
- memcpy( thisClass->recvImageBufR , recvBuf + tempcount , recvLen - tempcount );
- thisClass->recvBytePointerR = recvLen - tempcount;
- }
- }
- }
- }
- }
-
- }
- closesocket(m_serverSocket);
- WSACleanup();
- return TRUE;
- }
- UINT ThreadL( LPVOID g)
- {
- WSADATA wsa;
- /* initialize socket */
- WSAStartup(MAKEWORD(1,1),&wsa);
- Ctest2eyesDlg * thisClass = (Ctest2eyesDlg*)g;
- SOCKET m_serverSocket;
- /* create socket */
- m_serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- SOCKADDR_IN serverAddr;
- ZeroMemory((char *)&serverAddr,sizeof(serverAddr));
- serverAddr.sin_family = AF_INET;
- serverAddr.sin_port = htons(5565);
- serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- /* bind socket */
- bind(m_serverSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
- struct sockaddr_in daddr;
- memset((void *)&daddr,0,sizeof(daddr));
- daddr.sin_family=AF_INET;
- daddr.sin_port=htons(80);
- CString str1 ;
- thisClass->m_lip->GetWindowText(str1);
- char lip[40];
- wcstombs(lip , str1.GetBuffer() , 39 );
- daddr.sin_addr.s_addr=inet_addr(lip);
- int error = connect(m_serverSocket,(struct sockaddr *)&daddr,sizeof(daddr));
- const char * buf = "GET /MJPEG.CGI HTTP/1.0rnrn";
- fd_set fdRead; /* Read concourse define. */
- int ret; /* Return value. */
- TIMEVAL aTime; /* Event wait time define. */
- char recvBuf[RECV_BUF_SIZE];
- int allcount = 0;
- aTime.tv_sec = 1;
- aTime.tv_usec = 0;
- int recvLen;
- int f_recv = F_RECEIVE_NOWORKL;
- send( m_serverSocket,buf,100,0);
- TRACE(__T("Left Socket ok.rn"));
- while (thisClass->m_ThreadExit == FALSE)
- {
- if (thisClass->m_LeftReceived == TRUE)
- {
- TRACE(__T("Left Wait for Processing.rn"));
- Sleep(10);
- continue;
- }
- TRACE(__T("Left Receiving.rn"));
- /* Set empty to the fdRead Event. */
- FD_ZERO(&fdRead);
- /* Set read event to the client socket. */
- FD_SET(m_serverSocket,&fdRead);
- /* To judge whether there is any read event. */
- ret = select(0,&fdRead,NULL,NULL,&aTime);
- if (ret > 0)
- {
- if (FD_ISSET(m_serverSocket,&fdRead))
- {
- /* read event happen */
- recvLen = 0;
- /* recieve data */
- memset( recvBuf , 0 , RECV_BUF_SIZE );
- recvLen = recv( m_serverSocket , recvBuf , RECV_BUF_SIZE , 0 );
- if( recvLen <= 0 )
- {
- TRACE( _T( "Left TCP recive nothing.rn" ) );
- continue;
- }
- if( F_RECEIVE_NOWORKL == f_recv )
- {
- int tempcount;
- for( tempcount = 0 ; tempcount < recvLen - 1 ; tempcount++ )
- {
- if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- {
- f_recv = F_RECEIVE_BEGINL;
- break;
- }
- }
- if( F_RECEIVE_BEGINL == f_recv )
- {
- f_recv = F_RECEIVEL;
- thisClass->recvBytePointerL = 0;
- memcpy( thisClass->recvImageBufL , recvBuf + tempcount , recvLen - tempcount );
- thisClass->recvBytePointerL = recvLen - tempcount;
- }
- }
- else if( F_RECEIVEL == f_recv )
- {
- int tempcount;
- for( tempcount = 0 ; tempcount < recvLen ; tempcount++ )
- {
- if( ( recvBuf[tempcount - 2] == (char)0xFF ) && ( recvBuf[tempcount - 1] == (char)0xD9 ) )
- {
- f_recv = F_RECEIVE_OVER_L;
- break;
- }
- }
- if( F_RECEIVEL == f_recv ) /* 未接收完一个文件 */
- {
- memcpy( thisClass->recvImageBufL + thisClass->recvBytePointerL , recvBuf , recvLen );
- thisClass->recvBytePointerL += recvLen;
- }
- else if( F_RECEIVE_OVER_L == f_recv ) /* 接收完一个文件 */
- {
- memcpy( thisClass->recvImageBufL + thisClass->recvBytePointerL , recvBuf , tempcount );
- thisClass->recvBytePointerL += tempcount;
- CString strL;
- strL.Format( __T("D:\project\pic\002.jpg") , 1 );
- TRACE(__T("Left Received file.rn"));
- CFile ka;
- if( ka.Open( strL , CFile::modeCreate | CFile::modeReadWrite ) == TRUE )
- {
- TRACE(__T("Left Writting file.rn"));
- ka.SeekToBegin();
- ka.Write( thisClass->recvImageBufL , thisClass->recvBytePointerL );
- ka.Close();
- thisClass->m_LeftReceived = TRUE;
- }
- TRACE(__T("Left Received done.rn"));
- if( thisClass->f_MutexImageBufL == MUTEX_NONUSE )
- {
- thisClass->f_MutexImageBufL = MUTEX_USE;
- memcpy(thisClass->imageBufL.buf , thisClass->recvImageBufL , thisClass->recvBytePointerL );
- thisClass->imageBufL.size = thisClass->recvBytePointerL;
- thisClass->f_MutexImageBufL = MUTEX_NONUSE;
- }
- f_recv = F_RECEIVE_NOWORKL;
- for( ; tempcount < recvLen - 1 ; tempcount++ )
- {
- if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- {
- f_recv = F_RECEIVE_BEGINL;
- break;
- }
- }
- if( F_RECEIVE_BEGINL == f_recv )
- {
- f_recv = F_RECEIVEL;
- thisClass->recvBytePointerL = 0;
- memcpy( thisClass->recvImageBufL , recvBuf + tempcount , recvLen - tempcount );
- thisClass->recvBytePointerL = recvLen - tempcount;
- }
- }
- }
- }
- }
- }
- closesocket(m_serverSocket);
- WSACleanup();
- return TRUE;
- }
- //UINT ThreadL( LPVOID p)
- //{
- // WSADATA wsa;
- // /* initialize socket */
- // WSAStartup(MAKEWORD(1,1),&wsa);
- // Ctest2eyesDlg * thisClass = (Ctest2eyesDlg*)p;
- //
- // SOCKET m_serverSocket;
- //
- // /* initialize socket */
- //
- // /* create socket */
- // m_serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- //
- // SOCKADDR_IN serverAddr;
- // ZeroMemory((char *)&serverAddr,sizeof(serverAddr));
- // serverAddr.sin_family = AF_INET;
- // serverAddr.sin_port = htons(5565);
- // serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- //
- // /* bind socket */
- // bind(m_serverSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
- //
- // struct sockaddr_in daddr;
- // memset((void *)&daddr,0,sizeof(daddr));
- // daddr.sin_family=AF_INET;
- // daddr.sin_port=htons(80);
- //
- //
- // CString str1 ;
- //
- // thisClass->m_lip->GetWindowText(str1);
- //
- // char lip[40];
- //
- // wcstombs(lip , str1.GetBuffer() , 39 );
- //
- // daddr.sin_addr.s_addr=inet_addr(lip);
- // int error = connect(m_serverSocket,(struct sockaddr *)&daddr,sizeof(daddr));
- // const char * buf = "GET /MJPEG.CGI HTTP/1.0rnrn";
- //
- //
- // fd_set fdRead; /* Read concourse define. */
- // int ret; /* Return value. */
- // TIMEVAL aTime; /* Event wait time define. */
- //
- // char recvBuf[RECV_BUF_SIZE];
- // int allcount = 0;
- //
- // aTime.tv_sec = 1;
- // aTime.tv_usec = 0;
- //
- // int recvLen;
- //
- // int f_recv = F_RECEIVE_NOWORKL;
- //
- // send( m_serverSocket,buf,100,0);
- //
- // TRACE(__T("Left Socket ok.rn"));
- // while (thisClass->m_ThreadExit == FALSE)
- // {
- //
- // if (thisClass->m_LeftReceived == TRUE)
- // {
- // //Sleep(10);
- // //continue;
- // }
- // /* Set empty to the fdRead Event. */
- // FD_ZERO(&fdRead);
- //
- // /* Set read event to the client socket. */
- // FD_SET(m_serverSocket,&fdRead);
- //
- // /* To judge whether there is any read event. */
- // ret = select(0,&fdRead,NULL,NULL,&aTime);
- // if (ret > 0)
- // {
- //
- // if (FD_ISSET(m_serverSocket,&fdRead))
- // {
- // /* read event happen */
- // recvLen = 0;
- //
- // /* recieve data */
- // memset( recvBuf , 0 , RECV_BUF_SIZE );
- // recvLen = recv( m_serverSocket , recvBuf , RECV_BUF_SIZE , 0 );
- //
- // if( recvLen <= 0 )
- // {
- // TRACE( _T( "TCP recive nothing ln" ) );
- // continue;
- // }
- //
- // if( F_RECEIVE_NOWORKL == f_recv )
- // {
- // int tempcount;
- // for( tempcount = 0 ; tempcount < recvLen - 1 ; tempcount++ )
- // {
- // if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- // {
- // f_recv = F_RECEIVE_BEGINL;
- // break;
- // }
- // }
- //
- // if( F_RECEIVE_BEGINL == f_recv )
- // {
- // f_recv = F_RECEIVEL;
- // thisClass->recvBytePointerL = 0;
- // memcpy( thisClass->recvImageBufL , recvBuf + tempcount , recvLen - tempcount );
- // thisClass->recvBytePointerL = recvLen - tempcount;
- // }
- // }
- // else if( F_RECEIVEL == f_recv )
- // {
- // int tempcount;
- // for( tempcount = 0 ; tempcount < recvLen ; tempcount++ )
- // {
- // if( ( recvBuf[tempcount - 2] == (char)0xFF ) && ( recvBuf[tempcount - 1] == (char)0xD9 ) )
- // {
- // f_recv = F_RECEIVE_OVER_L;
- // break;
- // }
- // }
- //
- // if( F_RECEIVEL == f_recv ) /* 未接收完一个文件 */
- // {
- // memcpy( thisClass->recvImageBufL + thisClass->recvBytePointerL , recvBuf , recvLen );
- // thisClass->recvBytePointerL += recvLen;
- // }
- // else if( F_RECEIVE_OVER_L == f_recv ) /* 接收完一个文件 */
- // {
- // memcpy( thisClass->recvImageBufL + thisClass->recvBytePointerL , recvBuf , tempcount );
- // thisClass->recvBytePointerL += tempcount;
- //
- // CString strR;
- //
- // strR.Format( __T("D:\project\pic\002.jpg") , 1 );
- //
- // CFile ka;
- // if( ka.Open( strR , CFile::modeCreate | CFile::modeReadWrite ) == TRUE )
- // {
- // ka.SeekToBegin();
- // ka.Write( thisClass->recvImageBufL , thisClass->recvBytePointerL );
- // ka.Close();
- // thisClass->m_LeftReceived = TRUE;
- // }
- //
- // if( thisClass->f_MutexImageBufL == MUTEX_NONUSE )
- // {
- // thisClass->f_MutexImageBufL = MUTEX_USE;
- // memcpy(thisClass->imageBufL.buf , thisClass->recvImageBufL , thisClass->recvBytePointerL );
- //
- //
- // thisClass->imageBufL.size = thisClass->recvBytePointerL;
- // thisClass->f_MutexImageBufL = MUTEX_NONUSE;
- // }
- //
- // f_recv = F_RECEIVE_NOWORKL;
- //
- // for( ; tempcount < recvLen - 1 ; tempcount++ )
- // {
- // if( ( recvBuf[tempcount] == (char)0xFF ) && ( recvBuf[tempcount + 1] == (char)0xD8 ) )
- // {
- // f_recv = F_RECEIVE_BEGINL;
- // break;
- // }
- // }
- //
- // if( F_RECEIVE_BEGINL == f_recv )
- // {
- // f_recv = F_RECEIVEL;
- // thisClass->recvBytePointerL = 0;
- // memcpy( thisClass->recvImageBufL , recvBuf + tempcount , recvLen - tempcount );
- // thisClass->recvBytePointerL = recvLen - tempcount;
- // }
- //
- // }
- // }
- // }
- // }
- // }
- //
- //
- // closesocket(m_serverSocket);
- // WSACleanup();
- //
- // return TRUE;
- //}
- //
- //
- void Ctest2eyesDlg::OnBnClickedButton1()
- {
- }
- void Ctest2eyesDlg::OnTimer(UINT_PTR nIDEvent)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- switch(nIDEvent)
- {
- case MYTIMER:
- {
- if (m_LeftReceived == TRUE && m_RightReceived == TRUE)
- {
- if (m_processing == FALSE)
- {
- test_SIFT();
- }
- }
- }
- break;
- default:
- KillTimer(MYTIMER);
- break;
- }
- CDialog::OnTimer(nIDEvent);
- }
- HBRUSH Ctest2eyesDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- switch(nCtlColor)
- {
- case CTLCOLOR_STATIC:
- switch(pWnd->GetDlgCtrlID())
- {
- case IDC_STATIC_ICON:
- {
- return m_BMPDisplayBrush;
- }
- break;
- }
- }
- return hbr;
- }
- void Ctest2eyesDlg::OnBnClickedCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- m_ThreadExit = TRUE;
- exit(1);
- OnCancel();
- }