[英]Taking R,G,B individually from a <cv::vec3b> vector
To make my question clearer, please see the codes. 为了使我的问题更清楚,请参阅代码。
vector<cv::Vec3b> v_char; // the vector that I am storing my r,g,b values, or b,g,r in this case since it's opencv.
I know to print out the value of use the values, I can just simply take from image directly, something like this. 我知道要打印出使用值的值,我可以直接从图像中直接获取,类似这样。
b = image.at<cv::Vec3b>(i,j)[0];
g = image.at<cv::Vec3b>(i,j)[1];
r = image.at<cv::Vec3b>(i,j)[2];
However, without the use of the image(imagine image is gone), and I only want the values from the vector, v_char where all the image values have been stored, let's say for instance, I only want the r value, how do I retrieve it? 但是,在不使用图像的情况下(想象的图像消失了),我只想要存储所有图像值的向量v_char中的值,例如,我只想要r值,我该如何找回它? Tried searching it up on the internet and playing around with the codes, but to no avail :( 试图在互联网上搜索它并尝试使用代码,但无济于事:(
EDIT: MORE DETAILS The vector, v_char is just storing the value of one row of the image. 编辑:更多详细信息向量v_char仅存储图像的一行的值。 So for example: I want to find and print out all the r values of the particular row which can be found in the v_char vector. 因此,例如:我想查找并打印出可以在v_char向量中找到的特定行的所有r值。 I can use a for loop, but how do I declare out the r values only? 我可以使用for循环,但是如何只声明r值呢?
Vec3b v_char
itself is a vector of 3 values which can be accessed as first values = v_char.val[0]
, second values = v_char.val[1]
, third values = v_char.val[2]
. Vec3b v_char
本身是3个值的向量,可以作为first values = v_char.val[0]
, second values = v_char.val[1]
, third values = v_char.val[2]
。 As you need only the red
values so, just access all the values in v_char.val[0]
for the whole vector. 由于只需要red
值,因此只需访问v_char.val[0]
中的整个矢量的所有值v_char.val[0]
。
so through a for loop
try to get all the values of: 因此,通过for loop
尝试获取以下所有值:
v_char[i].val[0]; // "i" represents the index of "for loop" for a given row
It's difficult to know without knowing your data structure, but likely something like this. 在不知道您的数据结构的情况下很难知道,但可能是这样的。
Assuming j
is the row index, i
is the column index, and the stride of your rows is neatly packed. 假设j
是行索引, i
是列索引,并且行的步幅被整齐地打包。
auto &px = v_char[j * width + i];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.