I guess your matrix need to be of type CV_8UC1, ie. Mat mask = cv::Mat::zeros(rows, cols, CV_8UC1), or easier: just use Mat1b mask = cv::Mat1b::zeros(rows,cols), then set the areas to one where you would like to detect keypoints.