First time here? Check out the FAQ!

Ask Your Question
1

copy data to cv::Mat with specific type assigned by the user

asked Dec 27 '13

stereoMatching gravatar image

updated Oct 29 '0

cv::Mat A(3, 3, CV_8UC1);
cv::Mat B;
B.create(A.size(), CV_32FC1);
std::cout<<A.type()<<", "<<B.type()<<std::endl;
A.copyTo(B);
std::cout<<A.type()<<", "<<B.type()<<std::endl;

I want to copy A to B without changing the type of B.

Any clean solution to do this without writing explicit loop?Thanks

ps : I don't want to convert B to CV_32FC1 after copied

Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered Dec 27 '13

Vladislav Vinogradov gravatar image

Use convertTo method:

A.convertTo(B, B.type());
Preview: (hide)

Question Tools

Stats

Asked: Dec 27 '13

Seen: 327 times

Last updated: Dec 27 '13