# \#mat

**URL:** https://forum.opencv.org/tag/mat/29.md

[Latest](https://forum.opencv.org/latest.md) · [Categories](https://forum.opencv.org/categories.md) · [Tags](https://forum.opencv.org/tags.md)

---

## [Resize a mat containing CV\_8UC2](https://forum.opencv.org/t/resize-a-mat-containing-cv-8uc2/20082)

<div class="topic-metadata">

**Author:** [@msearancke](https://forum.opencv.org/u/msearancke)\
**Replies:** 0\
**Last updated:** [February 3, 2025, 3:57am UTC](https://forum.opencv.org/t/resize-a-mat-containing-cv-8uc2/20082 "2025-02-03T03:57:11Z")

</div>

I am trying to track down a memory corruption in a routine that crops and resizes an UYVY frame (NDI is the source) but I am not sure if the cv::resize function works for a 2 byte per pixel map (type = CV\_8UC2). If I re…

---

## [Mat and a stack of images](https://forum.opencv.org/t/mat-and-a-stack-of-images/18265)

<div class="topic-metadata">

**Author:** [@Loic74650](https://forum.opencv.org/u/Loic74650)\
**Replies:** 4\
**Last updated:** [July 14, 2024, 1:36pm UTC](https://forum.opencv.org/t/mat-and-a-stack-of-images/18265 "2024-07-14T13:36:26Z")

</div>

Greetings, Loic here, new to this forum and to OpenCV (C++) but not to Computer Vision. I have a basic question: I wish to load a stack of color images and generate new color images from the image stack by extracting t…

---

## [Create openCV Matrix from rotated CVPixelBufferRef in iOS](https://forum.opencv.org/t/create-opencv-matrix-from-rotated-cvpixelbufferref-in-ios/17699)

<div class="topic-metadata">

**Author:** [@SSRat](https://forum.opencv.org/u/SSRat)\
**Replies:** 1\
**Last updated:** [May 20, 2024, 6:24pm UTC](https://forum.opencv.org/t/create-opencv-matrix-from-rotated-cvpixelbufferref-in-ios/17699 "2024-05-20T18:24:47Z")

</div>

I have a live video feed connected to an MLModel. In order to get the correct normalized coordinates from the MLModel’s detections, I set the AVCaptureConnection’s videoOrientation value to “Portrait”. This works great …

---

## [Qr detector Opencv.js Polylines from points](https://forum.opencv.org/t/qr-detector-opencv-js-polylines-from-points/17270)

<div class="topic-metadata">

**Author:** [@Rc1025](https://forum.opencv.org/u/Rc1025)\
**Replies:** 1\
**Last updated:** [April 13, 2024, 7:59pm UTC](https://forum.opencv.org/t/qr-detector-opencv-js-polylines-from-points/17270 "2024-04-13T19:59:06Z")

</div>

I’m trying to replicate some code from rust/python-bindings to html with js however the points (cv.Mat) seems to be different than the what is returned in these other bindings. For example: Python import cv2 cap = cv2.…

---

## [Why does use local variable in Mat::resize()?](https://forum.opencv.org/t/why-does-use-local-variable-in-mat-resize/15988)

<div class="topic-metadata">

**Author:** [@whiplash](https://forum.opencv.org/u/whiplash)\
**Replies:** 4\
**Last updated:** [January 2, 2024, 12:37am UTC](https://forum.opencv.org/t/why-does-use-local-variable-in-mat-resize/15988 "2024-01-02T00:37:51Z")

</div>

in the function of Mat::resize(), line 1048 & 1049, where dose use local variable ‘part’, is it valid that assign ‘s’ to ‘part’? or ‘part’ here means the ‘Mat’ object itself ?

---

## [How to let cv::Mat constructed in a pre-allocated memory?](https://forum.opencv.org/t/how-to-let-cv-mat-constructed-in-a-pre-allocated-memory/14874)

<div class="topic-metadata">

**Author:** [@mactarvish](https://forum.opencv.org/u/mactarvish)\
**Replies:** 0\
**Last updated:** [October 16, 2023, 8:59am UTC](https://forum.opencv.org/t/how-to-let-cv-mat-constructed-in-a-pre-allocated-memory/14874 "2023-10-16T08:59:04Z")

</div>

In embedding development using pure C, we usually pre-allocate a continuous memory before executing cv algorithm, and don’t allocate new memory in runtime (execpt little temp variables on stack) for better memory managem…

---

## [Opencv.js (Javascript) How can I create a contour (Mat) object with vertices coordinates in an array](https://forum.opencv.org/t/opencv-js-javascript-how-can-i-create-a-contour-mat-object-with-vertices-coordinates-in-an-array/14046)

<div class="topic-metadata">

**Author:** [@brotherseven](https://forum.opencv.org/u/brotherseven)\
**Replies:** 0\
**Last updated:** [July 28, 2023, 6:40am UTC](https://forum.opencv.org/t/opencv-js-javascript-how-can-i-create-a-contour-mat-object-with-vertices-coordinates-in-an-array/14046 "2023-07-28T06:40:07Z")

</div>

Hi there, This is a question about using opencv.js (Javascript): How can I properly create a contour (Mat) object with vertices coordinates in an array, such as \[\[1,2\],\[3,4\],\[5,6\],\[7,8\]\]? Regards Richard

---

## [How to store 4D mat of dimension \[1\*224\*224\*1\*CV\_32FC1\] to Bitmap Image](https://forum.opencv.org/t/how-to-store-4d-mat-of-dimension-1-224-224-1-cv-32fc1-to-bitmap-image/13532)

<div class="topic-metadata">

**Author:** [@Arya\_Pulkit](https://forum.opencv.org/u/Arya_Pulkit)\
**Replies:** 2\
**Last updated:** [June 20, 2023, 11:22am UTC](https://forum.opencv.org/t/how-to-store-4d-mat-of-dimension-1-224-224-1-cv-32fc1-to-bitmap-image/13532 "2023-06-20T11:22:50Z")

</div>

the DNN model is giving the output in mat \[1\*224\*224\*1\*CV\_32FC1\] format how do we convert mat type to bitmap . i am trying : Mat resultBitmap = detections.reshape(1,224,224); Bitmap bitmap = Bitmap.createBitmap(mat3D.…

---

## [Usage of UMat and Mat](https://forum.opencv.org/t/usage-of-umat-and-mat/4828)

<div class="topic-metadata">

**Author:** [@Mustafa\_Bay](https://forum.opencv.org/u/Mustafa_Bay)\
**Replies:** 6\
**Last updated:** [April 24, 2023, 3:13pm UTC](https://forum.opencv.org/t/usage-of-umat-and-mat/4828 "2023-04-24T15:13:26Z")

</div>

Hi Everyone, I am using OpenCV 4.1.2 and I want to understand usage of UMat and Mat. I wonder that when I retrieve an UMat from Mat by using getUMat() function, what happen if I make a change on UMat. Is Mat changed at …

---

## [Avoid confusion of matrix types](https://forum.opencv.org/t/avoid-confusion-of-matrix-types/11147)

<div class="topic-metadata">

**Author:** [@felixn](https://forum.opencv.org/u/felixn)\
**Replies:** 1\
**Last updated:** [December 5, 2022, 5:36pm UTC](https://forum.opencv.org/t/avoid-confusion-of-matrix-types/11147 "2022-12-05T17:36:42Z")

</div>

Hi, as my code is growing (and the time since I wrote some of it increasing), I find myself more and more confronted to the problem of calling functions with the wrong matrix type (for example matrix of uchar instead of…

---

## [How can I copy elements from one type of Mat to a different type of Mat](https://forum.opencv.org/t/how-can-i-copy-elements-from-one-type-of-mat-to-a-different-type-of-mat/9770)

<div class="topic-metadata">

**Author:** [@mdresser](https://forum.opencv.org/u/mdresser)\
**Replies:** 2\
**Last updated:** [August 9, 2022, 12:46pm UTC](https://forum.opencv.org/t/how-can-i-copy-elements-from-one-type-of-mat-to-a-different-type-of-mat/9770 "2022-08-09T12:46:51Z")

</div>

I am trying to copy 16 bit monochrome values (16UC1) to the blue and green channels of an 8UC3 mat. The commented lines will do what I want but involve several math operations per pixel. It should be faster to directly…

---

## [How to store Mat in std::array](https://forum.opencv.org/t/how-to-store-mat-in-std-array/9179)

<div class="topic-metadata">

**Author:** [@toe](https://forum.opencv.org/u/toe)\
**Replies:** 3\
**Last updated:** [June 15, 2022, 7:48am UTC](https://forum.opencv.org/t/how-to-store-mat-in-std-array/9179 "2022-06-15T07:48:50Z")

</div>

I am trying to save six unique Mat’s in one array array\<Mat, 6\> faceScans; and access them later in my program. Simple assignment didn’t work as it just overrode previous data faceScans\[0\] = img(ROI); I was just won…

---

## [Convert Mat Image to uint32\_t type](https://forum.opencv.org/t/convert-mat-image-to-uint32-t-type/6619)

<div class="topic-metadata">

**Author:** [@clyde\_Bailey](https://forum.opencv.org/u/clyde_Bailey)\
**Replies:** 1\
**Last updated:** [December 9, 2021, 9:59am UTC](https://forum.opencv.org/t/convert-mat-image-to-uint32-t-type/6619 "2021-12-09T09:59:31Z")

</div>

Hey guys! Wanted to know how can I convert a mat image to a uint32\_t type data structure? TIA

---

## [Different order of elements while std::cout print a cv::Mat than to iterate with cv::Mat begin(), end()](https://forum.opencv.org/t/different-order-of-elements-while-std-cout-print-a-cv-mat-than-to-iterate-with-cv-mat-begin-end/5765)

<div class="topic-metadata">

**Author:** [@Israel\_Diaz](https://forum.opencv.org/u/Israel_Diaz)\
**Replies:** 1\
**Last updated:** [October 21, 2021, 12:19pm UTC](https://forum.opencv.org/t/different-order-of-elements-while-std-cout-print-a-cv-mat-than-to-iterate-with-cv-mat-begin-end/5765 "2021-10-21T12:19:09Z")

</div>

I have the following code to obtain a 32FC3 cv::Mat cv::Mat imageBGR = cv::imread(imageFilepath, cv::ImreadModes::IMREAD\_COLOR); cv::Mat resizedImageBGR, resizedImageRGB, resizedImage, preprocessedImage; cv::resize(imag…

---

## [How can i access to the stats of the connectedComponentsWithStats function?](https://forum.opencv.org/t/how-can-i-access-to-the-stats-of-the-connectedcomponentswithstats-function/4700)

<div class="topic-metadata">

**Author:** [@credox](https://forum.opencv.org/u/credox)\
**Replies:** 3\
**Last updated:** [August 11, 2021, 5:47am UTC](https://forum.opencv.org/t/how-can-i-access-to-the-stats-of-the-connectedcomponentswithstats-function/4700 "2021-08-11T05:47:23Z")

</div>

i cant access the stats by following the description! or at method from the internet .help me please!

---

## [Why ROI not changed](https://forum.opencv.org/t/why-roi-not-changed/4659)

<div class="topic-metadata">

**Author:** [@Shahryar](https://forum.opencv.org/u/Shahryar)\
**Replies:** 1\
**Last updated:** [August 8, 2021, 2:04pm UTC](https://forum.opencv.org/t/why-roi-not-changed/4659 "2021-08-08T14:04:28Z")

</div>

hi everybody consider the following code: cv::Mat out (1000,1,CV\_64FC1,cv::Scalar::all(10)); cv::Mat out2 (186,186,CV\_64FC1,cv::Scalar::all(20)); cv::Mat diag\_i = out2.diag(0); auto rect = cv::Rect(0, 5, 1, 1000); …

---

## [Opencv matrix multiplication](https://forum.opencv.org/t/opencv-matrix-multiplication/4649)

<div class="topic-metadata">

**Author:** [@Shahryar](https://forum.opencv.org/u/Shahryar)\
**Replies:** 1\
**Last updated:** [August 7, 2021, 11:30am UTC](https://forum.opencv.org/t/opencv-matrix-multiplication/4649 "2021-08-07T11:30:08Z")

</div>

Hi everybody, i found that when i multiply vector in vector the run time is much more than when i multiply matrix in matrix in OpenCV 2.4.7 consider that both of the vector and matrices has the same number of multiplic…

---

## [Why does .clone() doesn't copy rows?](https://forum.opencv.org/t/why-does-clone-doesnt-copy-rows/4349)

<div class="topic-metadata">

**Author:** [@Pablo\_R](https://forum.opencv.org/u/Pablo_R)\
**Replies:** 1\
**Last updated:** [July 15, 2021, 11:51am UTC](https://forum.opencv.org/t/why-does-clone-doesnt-copy-rows/4349 "2021-07-15T11:51:33Z")

</div>

I got this code: cv::Mat mat { {3, 3, 3}, CV\_8UC3}; auto mat2 = mat.clone(); To have two copies of the same matrix, but mat2.rows != mat.rows\`, looks like data has been correctly copied, but all metadata doesn’t, whi…

---

## [1D array to 16bits greyscale mat](https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888)

<div class="topic-metadata">

**Author:** [@superdu](https://forum.opencv.org/u/superdu)\
**Replies:** 3\
**Last updated:** [June 17, 2021, 9:29am UTC](https://forum.opencv.org/t/1d-array-to-16bits-greyscale-mat/3888 "2021-06-17T09:29:01Z")

</div>

hello everyone. That make a long time now that im blocked and i didn’t find solutions yet. I really need your help. I have a 1d dynamical int array which represent a grayscale image of 8288x5644 pixels. I try to displ…

---

## [How to deal with large images](https://forum.opencv.org/t/how-to-deal-with-large-images/952)

<div class="topic-metadata">

**Author:** [@Franco\_Chacon](https://forum.opencv.org/u/Franco_Chacon)\
**Replies:** 15\
**Last updated:** [June 5, 2021, 11:32am UTC](https://forum.opencv.org/t/how-to-deal-with-large-images/952 "2021-06-05T11:32:24Z")

</div>

Hi, for example, I have a very large image that weighs 3 GB opened on RAM I want to do some operations that create a copy of the image like a color conversion and threshold So I have this… import numpy as np import cv…

---

## [How to loose pixel ownership of a Mat](https://forum.opencv.org/t/how-to-loose-pixel-ownership-of-a-mat/3175)

<div class="topic-metadata">

**Author:** [@zana](https://forum.opencv.org/u/zana)\
**Replies:** 4\
**Last updated:** [May 6, 2021, 10:56am UTC](https://forum.opencv.org/t/how-to-loose-pixel-ownership-of-a-mat/3175 "2021-05-06T10:56:46Z")

</div>

Hi I have a Mat and I want to pass its data to another container without copying. I want to make the Mat no longer possess ownership of that data because if it has the ownership, then it will try to release it at the en…

---

## [Analyze RGB Videostream](https://forum.opencv.org/t/analyze-rgb-videostream/3027)

<div class="topic-metadata">

**Author:** [@makoe91](https://forum.opencv.org/u/makoe91)\
**Replies:** 7\
**Last updated:** [April 28, 2021, 12:56pm UTC](https://forum.opencv.org/t/analyze-rgb-videostream/3027 "2021-04-28T12:56:26Z")

</div>

Hi, i’am new to OpenCV and have a general question. Is it possible to analyze the RGB values of a videostream with the OpenCV library? I found many information about converting color spaces, but nothing about reading co…

---

## [When using a threshold, how can I tell which of the pixels are collected?](https://forum.opencv.org/t/when-using-a-threshold-how-can-i-tell-which-of-the-pixels-are-collected/2989)

<div class="topic-metadata">

**Author:** [@Zedespook](https://forum.opencv.org/u/Zedespook)\
**Replies:** 1\
**Last updated:** [April 26, 2021, 1:30pm UTC](https://forum.opencv.org/t/when-using-a-threshold-how-can-i-tell-which-of-the-pixels-are-collected/2989 "2021-04-26T13:30:00Z")

</div>

Hey there, :slight\_smile: Upon displaying a threshold result, it shows which pixels are being picked up by the algorithm, like it should be, but I was wondering if I can get the amount of pixels into an int variable? W…

---

## [How can I count how many black and white pixels are on a picture?](https://forum.opencv.org/t/how-can-i-count-how-many-black-and-white-pixels-are-on-a-picture/2936)

<div class="topic-metadata">

**Author:** [@Zedespook](https://forum.opencv.org/u/Zedespook)\
**Replies:** 1\
**Last updated:** [April 23, 2021, 9:11am UTC](https://forum.opencv.org/t/how-can-i-count-how-many-black-and-white-pixels-are-on-a-picture/2936 "2021-04-23T09:11:23Z")

</div>

Hello! After turning an image grayscale I figured the best solutions for one of my projects would be if I could count the amount of white pixels on a picture, is there a way to loop through the pixels on the picture and…

---

## [Cannot change pixel value of image](https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809)

<div class="topic-metadata">

**Author:** [@gvert](https://forum.opencv.org/u/gvert)\
**Replies:** 2\
**Last updated:** [April 17, 2021, 7:56am UTC](https://forum.opencv.org/t/cannot-change-pixel-value-of-image/2809 "2021-04-17T07:56:00Z")

</div>

I have the average RGB value of a region of an image (‘child’ in this case) and after I find the best image that has the closest RGB value to the one in child , I want to create another image by replacing the pixels in t…

---

## [Is it possible to display an matrix with an Bitdepth of 16 Bit (Colormap)](https://forum.opencv.org/t/is-it-possible-to-display-an-matrix-with-an-bitdepth-of-16-bit-colormap/2676)

<div class="topic-metadata">

**Author:** [@tim5](https://forum.opencv.org/u/tim5)\
**Replies:** 2\
**Last updated:** [April 9, 2021, 3:56pm UTC](https://forum.opencv.org/t/is-it-possible-to-display-an-matrix-with-an-bitdepth-of-16-bit-colormap/2676 "2021-04-09T15:56:41Z")

</div>

Hello, I would like to display an one channel Matrix with a bitdepth of more then 8 Bit because I have integers up to 3000. I found out that with Colormap it is only possible with CV\_8UC1. So it is only possible to dis…

---

## [Data type changed after .clone or copyTo](https://forum.opencv.org/t/data-type-changed-after-clone-or-copyto/2639)

<div class="topic-metadata">

**Author:** [@MakeItGreatAgain](https://forum.opencv.org/u/MakeItGreatAgain)\
**Replies:** 4\
**Last updated:** [April 7, 2021, 10:08am UTC](https://forum.opencv.org/t/data-type-changed-after-clone-or-copyto/2639 "2021-04-07T10:08:17Z")

</div>

hello, The original Mat is of double which we can see with .type() and elemSize1(). Another Mat object was declared in the same time as the original one. However, the data type of the other one is not the same after o…

---

## [Python representation of Mat with pointer to user data](https://forum.opencv.org/t/python-representation-of-mat-with-pointer-to-user-data/2239)

<div class="topic-metadata">

**Author:** [@Novruz97](https://forum.opencv.org/u/Novruz97)\
**Replies:** 7\
**Last updated:** [March 24, 2021, 1:15pm UTC](https://forum.opencv.org/t/python-representation-of-mat-with-pointer-to-user-data/2239 "2021-03-24T13:15:52Z")

</div>

Hello guys, how do I represent Mat (Size size, int type, void \*data, size\_t step=AUTO\_STEP) from docs in python? Im trying to change C++ code of someone to python, and Im stuck. Here is the code he wrote: rs2::frames…

---

## [Assign one image's index location to another image](https://forum.opencv.org/t/assign-one-images-index-location-to-another-image/2172)

<div class="topic-metadata">

**Author:** [@Vazabdul](https://forum.opencv.org/u/Vazabdul)\
**Replies:** 5\
**Last updated:** [March 15, 2021, 1:35pm UTC](https://forum.opencv.org/t/assign-one-images-index-location-to-another-image/2172 "2021-03-15T13:35:34Z")

</div>

I want to assign one image’s index location to another image’s i(current row) and j (current column) location. (I hope that this introduction clarified my situation.) Also, I need to mention I can only use openCV for I\\…

---

## [Problems creating a chroma key without mask on C++](https://forum.opencv.org/t/problems-creating-a-chroma-key-without-mask-on-c/2009)

<div class="topic-metadata">

**Author:** [@Rewcord](https://forum.opencv.org/u/Rewcord)\
**Replies:** 3\
**Last updated:** [March 7, 2021, 9:29pm UTC](https://forum.opencv.org/t/problems-creating-a-chroma-key-without-mask-on-c/2009 "2021-03-07T21:29:11Z")

</div>

Hi. I’m a student of Computer Science, and I’m doing a project in which i must to do a chroma key on a real time video, using RGB byte vectors. I have develop these code but did not work. void CET21CanalAlphaDlg::OnBnCl…

[Next page](https://forum.opencv.org/tag/mat/29.md?match_all_tags=true&page=1&tags%5B%5D=mat)
