c++ - OpenCV Unhandled Exception at 0x1050FBFE (opencv_world300.dll) -
**** ~~> updated <~~ **
hi, following error code below:
(my aim find special image on list of images called template matching. add opencv_world300 debug , release in visual studio 2012 don't know what's causing error)
unhandled exception @ 0x01ddabba (opencv_world300.dll) in opencv.exe: 0xc0000005: access violation reading location 0x0000fb97
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> void fastmatchtemplate(cv::mat& srca, cv::mat& srcb, cv::mat& dst, int maxlevel) { std::vector<cv::mat> refs, tpls, results; cv::buildpyramid(srca, refs, maxlevel); cv::buildpyramid(srcb, tpls, maxlevel); cv::mat ref, tpl, res; (int level = maxlevel; level >= 0; level--) { ref = refs[level]; tpl = tpls[level]; res = cv::mat::zeros(ref.size() + cv::size(1,1) - tpl.size(), cv_32fc1); if (level == maxlevel) { cv::matchtemplate(ref, tpl, res, cv_tm_ccorr_normed); } else { cv::mat mask; cv::pyrup(results.back(), mask); cv::mat mask8u; mask.convertto(mask8u, cv_8u); std::vector<std::vector<cv::point> > contours; cv::findcontours(mask8u, contours, cv_retr_external, cv_chain_approx_none); (int = 0; < contours.size(); i++) { cv::rect r = cv::boundingrect(contours[i]); cv::matchtemplate( ref(r + (tpl.size() - cv::size(1,1))), tpl, res(r), cv_tm_ccorr_normed ); } } // keep matches cv::threshold(res, res, 0.94, 1., cv_thresh_tozero); results.push_back(res); } res.copyto(dst); } int main() { cv::mat ref = cv::imread("g:\\reference.png"); cv::mat tpl = cv::imread("g:\\template.png"); if (ref.empty() || tpl.empty()) return -1; cv::mat ref_gray, tpl_gray; cv::cvtcolor(ref, ref_gray, cv_bgr2gray); cv::cvtcolor(tpl, tpl_gray, cv_bgr2gray); cv::mat dst; fastmatchtemplate(ref_gray, tpl_gray, dst, 2); while (true) { double minval, maxval; cv::point minloc, maxloc; cv::minmaxloc(dst, &minval, &maxval, &minloc, &maxloc); if (maxval >= 0.9) { cv::rectangle( ref, maxloc, cv::point(maxloc.x + tpl.cols, maxloc.y + tpl.rows), cv_rgb(0,255,0), 2 ); cv::floodfill( dst, maxloc, cv::scalar(0), 0, cv::scalar(.1), cv::scalar(1.) ); } else break; } cv::imshow("result", ref); cv::waitkey(); return 0; } thanks help!
Comments
Post a Comment