I have an image 16x16 pixel image , how can I put it in a matrix 1x256 pixel and then convert it back to a 16x16 pixel Using opencv ? I tried reshape but it didn't succeed as when i make cout<< image.cols << image.rows give me the same number which is 16,16 also sometimes the image is not continuous so reshape won't work Btw I need it in coding a neural network classifier.
答案 0 :(得分:0)
// create matrix for the result
Mat image1x256(Size(256,1), image.type());
// use reshape function
Mat image16x16 = image1x256.reshape(image.channels(), 16);
// copy the data from your image to new image
image.copyTo(image16x16);
由于image16x16和image1x256只是指向同一数据的不同指针,因此将数据复制到其中一个数据实际上会改变它们。
请注意,重塑函数会创建一个新标头(即新的智能指针),可以使用它而不是旧标头,但它不会更改仍然存在且可以使用的原始标头的属性。