Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Matrix element Serialization with OpenCV reshape function

Shulou Source: shulou.com Published: 2022-06-02 08:19:44 09月20日 Update

This article focuses on "how to use the OpenCV reshape function to serialize matrix elements", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to serialize matrix elements with OpenCV reshape functions.

In opencv, the reshape function is more interesting, it can not only change the number of channels of the matrix, but also serialize the matrix elements, a very useful function.

Function prototype:

Caterpillar: Mat Mat::reshape (int cn, int rows=0) const

There are few parameters, but you have to be careful when setting them.

Cn: indicates the number of channels (channels). If set to 0, the number of channels remains the same, otherwise it becomes the set number of channels.

Rows: represents the number of matrix rows. If set to 0, it means that the original number of rows remains the same, otherwise it becomes the set number of rows.

First set up an initial matrix: a matrix of 20 rows, 30 columns and 1 channel

Int main () {Mat data = Mat (20,30, CV_32F); / / set a matrix cout of 20 rows, 30 columns and 1 channel

Tags: Channel sequence matrix vector change function element time content result or learning practical deeper interesting interest prototype parameter comparison again Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Shulou Information MariaDB macOS