MPt* WuMatch_Pyrm( int* ptSum, CStdImage* imgL, int stBlkColL, int stBlkRowL, int nBlkColsL, int nBlkRowsL, CStdImage* imgR, int stBlkColR, int stBlkRowR, int nBlkColsR, int nBlkRowsR, CImagesCoorT* pCvt, float range, float zoomRate, float siftDist, float siftRatio, int mutual_best_match, const char* lpcstrTempDir ){ LogPrint(0, "\n<----SiftMatch_Pyrm starting[range= %.2f;zoom= %f]---->", range, zoomRate); *ptSum = 0; CSiftMatch matcher; if (!matcher.InitEnvi(GlobalParam::g_sift_match_gpu)) return NULL; CStdImage imgPyrmL, imgPyrmR; char strSiftPyrmL[512], strSiftPyrmR[512]; int nPyrmColsL, nPyrmRowsL, nPyrmColsR, nPyrmRowsR; float gsd_ratio = pCvt->get_gsd_ratio(); float zoomL = zoomRate*gsd_ratio; float zoomR = zoomRate; char strFile[512]; strcpy(strFile, lpcstrTempDir); char* pS = strFile + strlen(strFile); { sprintf(pS, "/%s_%d_%d_%d_%d_%.f.tif", imgL->GetImageName(), stBlkColL, stBlkRowL, nBlkColsL, nBlkRowsL, 1 / zoomL); BYTE* pBuf = NULL; FILE* fp = NULL; pBuf = new BYTE[int(nBlkColsL*nBlkRowsL*zoomL) + 8]; if (!pBuf) return NULL; imgL->ReadGray8(pBuf, stBlkColL, stBlkRowL, nBlkColsL, nBlkRowsL, zoomL, &nPyrmColsL, &nPyrmRowsL); if (!SaveImageFile(strFile, pBuf, nPyrmColsL, nPyrmRowsL, 1) || !imgPyrmL.Open(strFile)) { delete pBuf; return NULL; } delete pBuf; strcpy(strrchr(strFile, '.'), ".info"); fp = fopen(strFile, "w"); if (!fp) return NULL; fprintf(fp, "%d\t%d\t%d\t%d\t%f", stBlkColL, stBlkRowL, nBlkColsL, nBlkRowsL, zoomL); fclose(fp); strcpy(strrchr(strFile, '.'), ".sift"); strcpy(strSiftPyrmL, strFile); if (imgPyrmL.ExtractSift2PtFile(strSiftPyrmL, -1) < 1) return NULL; sprintf(pS, "/%s_%d_%d_%d_%d_%.f.tif", imgR->GetImageName(), stBlkColR, stBlkRowR, nBlkColsR, nBlkRowsR, 1 / zoomR); pBuf = new BYTE[int(nBlkColsR*nBlkRowsR*zoomR) + 8]; if (!pBuf) return NULL; imgR->ReadGray8(pBuf, stBlkColR, stBlkRowR, nBlkColsR, nBlkRowsR, zoomR, &nPyrmColsR, &nPyrmRowsR); if (!SaveImageFile(strFile, pBuf, nPyrmColsR, nPyrmRowsR, 1) || !imgPyrmR.Open(strFile)) { delete pBuf; return NULL; } delete pBuf; strcpy(strrchr(strFile, '.'), ".info"); fp = fopen(strFile, "w"); if (!fp) return NULL; fprintf(fp, "%d\t%d\t%d\t%d\t%f", stBlkColR, stBlkRowR, nBlkColsR, nBlkRowsR, zoomR); fclose(fp); strcpy(strrchr(strFile, '.'), ".sift"); strcpy(strSiftPyrmR, strFile); if (imgPyrmR.ExtractSift2PtFile(strSiftPyrmR, -1) < 1) return NULL; } int nColNum, nRowNum; int* rc_split = Pretreatment::split_image(nColNum, nRowNum, 0, 0, nPyrmColsL, nPyrmRowsL, 8, GlobalParam::g_match_buffer_size, Pretreatment::RECT_FIRST); int blk_num = nColNum*nRowNum; MPt* match_result = NULL; int *pSplitRc = rc_split; for (int i = 0; i < blk_num; i++, pSplitRc += 4){ LogPrint(0, ">>>>Pyrmblock<%.6f>[%d/%d]", zoomRate, i + 1, blk_num); int scr, srr, ncr, nrr; if (!pCvt->overlap_on_right(stBlkColL + pSplitRc[0] / zoomL, stBlkRowL + pSplitRc[1] / zoomL, stBlkColL + (pSplitRc[0] + pSplitRc[2]) / zoomL, stBlkRowL + (pSplitRc[1] + pSplitRc[3]) / zoomL, (int)range, (int)range, &scr, &srr, &ncr, &nrr)){ LogPrint(0, "no coverage.continue."); continue; } ncr = int((ncr - scr + 1)*zoomR); nrr = int((nrr - srr + 1)*zoomR); scr -= stBlkColR; srr -= stBlkRowR; // LogPrint(0, "left[%d,%d]+[%d,%d]<=>right[%d,%d]+[%d,%d]", // pSplitRc[0], pSplitRc[1], pSplitRc[2], pSplitRc[3], stBlkColR, stBlkRowR, nBlkColsR, nBlkRowsR); int ptNumL = imgPyrmL.ReadSiftFile(strSiftPyrmL, pSplitRc[0], pSplitRc[1], pSplitRc[2], pSplitRc[3]); if (ptNumL < 1) { LogPrint(0, "continue."); continue; } int ptNumR = imgPyrmR.ReadSiftFile(strSiftPyrmR, scr, srr, ncr, nrr); if (ptNumR < 1) { LogPrint(0, "continue."); continue; } int(*match_buf)[2] = new int[ptNumL>ptNumR ? ptNumL : ptNumR][2]; matcher.SetDescriptors(0, ptNumL, imgPyrmL.GetSiftDescriptors()); matcher.SetDescriptors(1, ptNumR, imgPyrmR.GetSiftDescriptors()); int match_num = matcher.GetSiftMatch(match_buf, siftDist, siftRatio, mutual_best_match); if (match_num > 0){ MPt* mpt = new MPt[*ptSum + match_num]; if (match_result) { memcpy(mpt, match_result, *ptSum*sizeof(MPt)); delete match_result; } match_result = mpt; MPt* pMPT = mpt + *ptSum; int sz = 0; int i; float lx0 = -99, ly0 = -99, rx0 = -99, ry0 = -99; for (i = 0; i < match_num; i++){ float* xyl = imgPyrmL.GetPtLocation() + match_buf[i][0] * 2; float* xyr = imgPyrmR.GetPtLocation() + match_buf[i][1] * 2; pMPT->xl = *xyl; pMPT->yl = *(xyl + 1); pMPT->xr = *xyr; pMPT->yr = *(xyr + 1); if (fabs(pMPT->xl - lx0) < 1e-5 && fabs(pMPT->yl - ly0) < 1e-5 && fabs(pMPT->xr - rx0) < 1e-5 && fabs(pMPT->yr - ry0) < 1e-5) continue; lx0 = pMPT->xl; ly0 = pMPT->yl; rx0 = pMPT->xr; ry0 = pMPT->yr; pMPT->xl = pMPT->xl / zoomL + stBlkColL; pMPT->yl = pMPT->yl / zoomL + stBlkRowL; pMPT->xr = pMPT->xr / zoomR + stBlkColR; pMPT->yr = pMPT->yr / zoomR + stBlkRowR; strcpy(pMPT->nameL, imgPyrmL.get_pt_name(match_buf[i][0])); strcpy(pMPT->nameR, imgPyrmR.get_pt_name(match_buf[i][1])); pMPT++; sz++; } LogPrint(0, "Remove repeat correspond points.Final Num= %d", sz); *ptSum += sz; } delete[] match_buf; } delete[] rc_split; LogPrint(0, "<----SiftMatch_Pyrm END[total num= %d][state= %s]---->\n", *ptSum, *ptSum<1 ? "Fail" : "OK"); return match_result; }
void Gbuf2File(char *str, int len, int adr) { SaveImageFile(str, gTransferBuf + adr, len); }