template matching - matchShapes using grayscale images opencv -
according matchshapes documentation, input can either gray scale images or contours. when tried 2 gray scale images, got assertion failed error. upon further exploration, found here mat object has 1d vector , of type cv_32fc2 or cv_32sc2.
using this answer, converted images vector array of float after converting them cv_32fc2. still assertion error.
can tell me how can compare 2 grayscale images using matchshapes function?
update
the error message
opencv error: assertion failed (contour1.checkvector(2) >= 0 && contour2.checkvector(2) >= 0 && (contour1.depth() == cv_32f || contour1.depth() == cv_32s) && contour1.depth() == contour2.depth()) in matchshapes, file /home/tonystark/opencv/modules/imgproc/src/contours.cpp, line 1936 terminate called after throwing instance of 'cv::exception' what(): /home/tonystark/opencv/modules/imgproc/src/contours.cpp:1936: error: (-215) contour1.checkvector(2) >= 0 && contour2.checkvector(2) >= 0 && (contour1.depth() == cv_32f || contour1.depth() == cv_32s) && contour1.depth() == contour2.depth() in function matchshapes when used
pkg-config --modversion opencv it says version 2.4.9
if break assertion message down, it's checking few things --
contour1.checkvector(2) >= 0 && contour2.checkvector(2) >= 0contour1.depth() == cv_32f || contour1.depth() == cv_32scontour1.depth() == contour2.depth()
it sounds aware of parts 2 , 3 above, i'll hazard guess it's failing on part 1.
according opencv documentation, checkvector function
returns n if matrix 1-channel (n x ptdim) or ptdim-channel (1 x n) or (n x 1); negative number otherwise
this unfortunately rather cryptic message. understand it, it's checking dimensionality of input dimension -- in case, failing assertion passing in 2, , verifying dimension greater 0. precludes possibility of having empty array, , verifies other dimension exists. tldr; it's checking if input 1d array of sufficient dimension.
i'd guess error result of passing in vector of vector of points -- instead, have pass in single 'shape' @ time matchshapes, i.e. vector of points
here's little test-case that, although not particularly interesting, should run without problems --
#include <cstdlib> #include <ctime> #include <iostream> #include <vector> #include <opencv2/opencv.hpp> int main(int argc, char* argv[]) { std::srand(std::time(0)); std::vector<cv::point> random_pointsa; (int = 0; < 1000; ++i) { auto rand_x = std::rand() % 255; auto rand_y = std::rand() % 255; random_pointsa.emplace_back(rand_x, rand_y); } std::vector<cv::point> random_pointsb; (int = 0; < 1000; ++i) { auto rand_x = std::rand() % 255; auto rand_y = std::rand() % 255; random_pointsb.emplace_back(rand_x, rand_y); } auto match_val = cv::matchshapes(random_pointsa, random_pointsb, cv_contours_match_i1, 0); std::cout << "match val: " << match_val << std::endl; }
Comments
Post a Comment