Answers for "opencv mat"

2

how to cout 4 dimensional cv::Mat

cv::Mat sliceMat(cv::Mat L,int dim,std::vector<int> _sz)
{
	cv::Mat M(L.dims - 1, std::vector<int>(_sz.begin() + 1, _sz.end()).data(), CV_8UC1, L.data + L.step[0] * 0);
	return M;
}


std::cout << "3 dimensions" << std::endl;

std::vector<int> sz = { 3,3,3 };

cv::Mat L;
L.create(3, sz.data(), CV_8UC1);
L = cv::Scalar(255);

std::cout<< sliceMat(L, 1, sz);

std::cout << std::endl;
std::cout <<"4 dimensions"<< std::endl;
sz = { 5,4,3,5 };
L.create(4, sz.data(), CV_8UC1);
L = cv::Scalar(255);
std::cout << sliceMat(sliceMat(L, 1, sz),2, std::vector<int>(sz.begin() + 1, sz.end()));
Posted by: Guest on November-25-2020

Browse Popular Code Answers by Language