2016-08-20 93 views
-3

我有一個C-API的OpenCV項目和我想改變成C++(墊) 看到此原代碼:錯誤:「 - >」的基礎操作數具有非指針型「CV ::墊」

current_cost = 0; 
basePtr = (unsigned char*)tmp1->imageData; 
for(int j=0; j<tmp1->height; basePtr += tmp1->widthStep, j++) 
{ 
    iterator = basePtr; 
    for(int i=0; i<tmp1->width; iterator++, i++) 
     if(*iterator == 255) 
      current_cost++; 
} 

basePtr = (unsigned char*)tmp2->imageData; 
for(int j=0; j < tmp2->height; basePtr += tmp2->widthStep, j++) 
{ 
    iterator = basePtr; 
    for(int i=0; i<tmp2->width; iterator++, i++) 
     if(*iterator == 0) 
      current_cost++; 
} 
if(current_cost < cost)     
    return true; 
else return false; 

運行這個項目之後,看到這個錯誤

main.cpp:63:35: error: base operand of ‘->’ has non-pointer type ‘cv::Mat’ 
basePtr = (unsigned char*)tmp1->imageData; 

看到錯誤使用的每一行 ' - >'。 請幫我...

+3

錯誤是告訴你,tmp1(等等)不是指針,而是具有類型cv :: Mat。所以,在這種情況下,我會假設處理這個問題的正確形式就像tmp1.imageData(等等)。但是這是一個猜測,因爲你沒有顯示足夠的代碼。 – Jauch

+0

嘗試使用'tmp1.imageData' – SimpleGuy

回答

0

你不應該只是轉換每一個代碼行,而是巧妙地使用C++ api。您的功能可能會改寫爲:

bool foo(const Mat& tmp1, const Mat& tmp2, int cost) { 
    int count = countNonZero(tmp1 == 255); 
    count += countNonZero(tmp2 == 0); 
    return count < cost; 
} 
相關問題