używam OpenCV w wersji 4.1.2 a więc najnowszej
kod konwertuje na Obj-C i używam w aplikacji iOS
EDIT: sciągnąłem wersje CV_VERSION = 3.4.8
https://sourceforge.net/projects/opencvlibrary/files/3.4.8/opencv-3.4.8-ios-framework.zip/download
wpiąłem w aplikację i crash jest ten sam:
wypis kompilatora:
libc++abi.dylib: terminating with uncaught exception of type cv: OpenCV(3.4.8) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/arithm.cpp error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op'
EDIT2:
użyłem kodu:
cv::Mat newMask = cv::Mat::zeros(mask.size(), mask.type());
for(int i=0; i< 3; i++) {
cv::Mat tray = cv::Mat::zeros(mask.size(),mask.type());
cv::inRange(mask, i+1, i+1, tray);
cv::erode(tray,tray,cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5,5)), cv::Point(-1,-1));
newMask += tray;
}
i nadal to samo
na slackoverlow dostałem informacje aby dodać:
cvtColor(newMask,newMask,CV_BGR2GRAY);
przed pętlą for ale wtedy wywala się w innym miejscu
cały kod po zmianach metody wygląda tak:
-
(Vec3f)getFeats:(Mat&)mask {
cout << "CV_VERSION = " << CV_VERSION << endl;
cv::Mat newMask = cv::zeros(mask.size(), mask.type());
for(int i=0; i< 3; i++) {
cv::Mat tray = cv::zeros(mask.size(),mask.type());
cv::inRange(mask, i+1, i+1, tray);
cv::erode(tray,tray,cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5,5)), cv::Point(-1,-1));
newMask += tray;
}
vector<vectorcv::Point > contours;
findContours( newMask, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE );
vector<float> v;
for( int i = 0; i< contours.size(); i++ ){
v.push_back(cv::contourArea(contours[i])/(mask.size[0]*mask.size[1]));
}
sort(v.begin(), v.end(), std::greater<float>());
return Vec3f(v[0], v[1], v[2]);
}
contours.size(); jest puste więc v tez jest puste i wywala
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
na ostatniej linii