The app is crashing while I am trying to scan the MRZ code on the passport. This is the log:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file ../matrix.cpp, line 517 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ../matrix.cpp:517: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat
Here is the stack trace:
#12 0x0062662c in cv::Mat::operator()(cv::Rect_ const&) const
#13 0x00628c72 in ::-[PassportScanner realProcessImage:](cv::Mat &)
Contents of the above function are as follows:
Mat Mat::operator()( const Rect& roi ) const
{
return Mat(*this, roi);
}
-(void) realProcessImage:(cv::Mat &)cropped {
//Some other code
vector<cv::Rect> rotatedRegions = [self show:cropped gray:rotated2];
// Sort by y
std::sort(rotatedRegions.begin(), rotatedRegions.end(), sortByBoundingRectYPosition);
if (rotatedRegions.size() == 2) {
if(self.delegate)
[self.delegate setVisualIndicatorColor:[PassportScanner getColorForFraction:0.5]];
while (rotatedRegions[0].height + rotatedRegions[0].y >= rotated.rows) {
rotatedRegions[0].height--;
}
image1 = rotated(rotatedRegions[0]);
while (rotatedRegions[1].height + rotatedRegions[1].y >= rotated.rows) {
rotatedRegions[1].height--;
}
image2 = rotated(rotatedRegions[1]); //**——>Problem starts here**
//More code
}
I have looked at these links but none of them helped me solve the problem:
Error with OpenCV ROI
OpenCv assertion failed