| | |
| | | int CInterfaceManager::LoadFullImage(CString strPath,int iSide,int nStartY, CGlass_Data *pGlassData,const bool bIsDebugImg) |
| | | { |
| | | int nHeight = -1; |
| | | if (strPath.IsEmpty() || iSide < 0 || iSide > MAX_DIMENSION_COUNT) { |
| | | g_pLog->DisplayMessage(_T("Load Full Image Fail(%s, %d)"), strPath, iSide); |
| | | return nHeight; |
| | | } |
| | | |
| | | #if 0 |
| | | USES_CONVERSION; |
| | | char str_filename[200]; |
| | | sprintf_s(str_filename, "%s", W2A(strPath)); |
| | | |
| | | IplImage *Iplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE); |
| | | LPBYTE lpImg = NULL; |
| | | IplImage* Iplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE); |
| | | g_pLog->DisplayMessage(_T("Image Size: %d x %d"), Iplimg->width, Iplimg->height); |
| | | |
| | | if(Iplimg) |
| | | { |
| | | if(bIsDebugImg == true) //Debug image |
| | | { |
| | | if (Iplimg) { |
| | | if (bIsDebugImg == true) { |
| | | UINT uiReadLine = 0; |
| | | |
| | | // lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY); |
| | | // if(lpImg != NULL) |
| | | // { |
| | | //if (lpImg != NULL) { |
| | | // memcpy(lpImg, &Iplimg->imageData[0] , Iplimg->widthStep*Iplimg->height); |
| | | // } |
| | | // |
| | | for(int i = 0; i < Iplimg->height; i++) |
| | | { |
| | | |
| | | for (int i = 0; i < Iplimg->height; i++) { |
| | | lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY+i); |
| | | if(lpImg == NULL) |
| | | break; |
| | |
| | | uiReadLine += Iplimg->widthStep; |
| | | } |
| | | |
| | | if(pGlassData != NULL) |
| | | { |
| | | if (pGlassData != NULL) { |
| | | INS_EDGE_RESULT_INFO *pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); |
| | | if(pResInfo != NULL) |
| | | { |
| | |
| | | nHeight = Iplimg->height; |
| | | cvReleaseImage(&Iplimg); |
| | | } |
| | | else //Full image |
| | | { |
| | | else { |
| | | //Full image |
| | | const double dRatio = 1.0 - static_cast<double>(IMAGE_COMPRESSRATIO / 100.0); |
| | | IplImage *resizeImage = cvCreateImage(cvSize((int)(Iplimg->width/dRatio), (int)(Iplimg->height/dRatio)), IPL_DEPTH_8U, 1); |
| | | |
| | |
| | | |
| | | |
| | | lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY); |
| | | if(lpImg != NULL) |
| | | { |
| | | if (lpImg != NULL) { |
| | | memcpy(lpImg, &Iplimg->imageData[0] , resizeImage->widthStep*resizeImage->height); |
| | | } |
| | | |
| | | // UINT uiReadLine = 0; |
| | | // for(int i = 0; i < resizeImage->height; i++) |
| | | // { |
| | | //for (int i = 0; i < resizeImage->height; i++) { |
| | | // lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY+i); |
| | | // if(lpImg == NULL) |
| | | // break; |
| | |
| | | // uiReadLine += resizeImage->widthStep; |
| | | // } |
| | | |
| | | if(pGlassData != NULL) |
| | | { |
| | | if (pGlassData != NULL) { |
| | | INS_EDGE_RESULT_INFO *pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); |
| | | if(pResInfo != NULL) |
| | | { |
| | | if (pResInfo != NULL) { |
| | | pResInfo->nGlassStartLine = 0; |
| | | pResInfo->nGlassEndLine = Iplimg->height + nStartY; |
| | | } |
| | |
| | | } |
| | | strPath.Append(_T("_OK")); |
| | | } |
| | | else |
| | | else { |
| | | strPath.Append(_T("_NG")); |
| | | } |
| | | #else |
| | | // 加载灰度图像 |
| | | std::string strFilename = CT2A(strPath); |
| | | cv::Mat img = cv::imread(strFilename, cv::IMREAD_GRAYSCALE); |
| | | |
| | | if (!img.empty()) { |
| | | g_pLog->DisplayMessage(_T("Image Size: %d x %d"), img.cols, img.rows); |
| | | |
| | | if (bIsDebugImg) { |
| | | for (int i = 0; i < img.rows; ++i) { |
| | | LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i); |
| | | if (lpImg == NULL) { |
| | | break; |
| | | } |
| | | |
| | | memcpy(lpImg, img.ptr(i), img.cols); |
| | | } |
| | | |
| | | if (pGlassData != NULL) { |
| | | INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); |
| | | if (pResInfo != NULL) { |
| | | pResInfo->nGlassStartLine = 0; |
| | | pResInfo->nGlassEndLine = img.rows + nStartY; |
| | | } |
| | | } |
| | | |
| | | nHeight = img.rows; |
| | | } |
| | | else { |
| | | // 按比例缩放 |
| | | const double dRatio = 1.0 - static_cast<double>(IMAGE_COMPRESSRATIO) / 100.0; |
| | | int newWidth = static_cast<int>(img.cols / dRatio); |
| | | int newHeight = static_cast<int>(img.rows / dRatio); |
| | | |
| | | cv::Size newSize(newWidth, newHeight); |
| | | cv::Mat resized; |
| | | cv::resize(img, resized, newSize, 0, 0, cv::INTER_CUBIC); |
| | | |
| | | LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY); |
| | | if (lpImg != NULL) { |
| | | memcpy(lpImg, resized.data, resized.cols * resized.rows); |
| | | } |
| | | |
| | | if (pGlassData != NULL) { |
| | | INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide); |
| | | if (pResInfo != NULL) { |
| | | pResInfo->nGlassStartLine = 0; |
| | | pResInfo->nGlassEndLine = resized.rows + nStartY; |
| | | } |
| | | } |
| | | |
| | | nHeight = resized.rows; |
| | | } |
| | | |
| | | strPath.Append(_T("_OK")); |
| | | } |
| | | else { |
| | | strPath.Append(_T("_NG")); |
| | | } |
| | | #endif // 0 |
| | | |
| | | g_pLog->DisplayMessage(_T("%s"),(TCHAR*)(LPCTSTR)strPath); |
| | | |
| | | SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0)); |
| | | |
| | | return nHeight; |