2016-08-20 1 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 (등)이 포인터 아니라고 말하고 않으며, 대신 형 이력서를 가지고 :: 매트 : 귀하의 기능을 간단하게 다시 작성할 수 있습니다. 그래서,이 경우, 나는 이것을 다루기위한 올바른 형식이 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; 
} 
관련 문제