Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何确定RGB或BGR中3通道的值_C++_Opencv - Fatal编程技术网

C++ 如何确定RGB或BGR中3通道的值

C++ 如何确定RGB或BGR中3通道的值,c++,opencv,C++,Opencv,这是我需要检测的图像 //cdst是图像 //这是我想知道某个像素值的代码,但下面的代码只检测第一个像素,然后第二个和第三个像素等于0 void dec() { Mat-em; cdst=“图像的路径”; //这是我希望检查的每种颜色的BGR值 Vec3f红色(0,0255); Vec3f蓝(255,0,0); Vec3f绿色(0,128,0); Vec3f黄色(0、255、255); Vec3f marron(00128); Vec3f粉红色(147,20255); Vec3f靛蓝(130,

这是我需要检测的图像

//cdst是图像
//这是我想知道某个像素值的代码,但下面的代码只检测第一个像素,然后第二个和第三个像素等于0
void dec()
{
Mat-em;
cdst=“图像的路径”;
//这是我希望检查的每种颜色的BGR值
Vec3f红色(0,0255);
Vec3f蓝(255,0,0);
Vec3f绿色(0,128,0);
Vec3f黄色(0、255、255);
Vec3f marron(00128);
Vec3f粉红色(147,20255);
Vec3f靛蓝(130,0,75);
Vec3f-中蓝(112,25,25);
Vec3f品红色(139,0,139);
//em将保存cdst映像
em=cdst;
//为循环确定什么是颜色
对于(int i=0;i试试这个代码怎么样

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(){

    Mat em(100, 100, CV_8UC3, Scalar::all(0));
    rectangle(em, Rect(30, 30, 10, 10), Scalar(147, 20, 255), -1);

    imshow("em", em);
    waitKey(1);

    Vec3b pink(147,20,255);
    for (int i = 0; i < em.rows; i++){
        for (int j = 0; j < em.cols; j++){
            Vec3b px = em.at<Vec3b>(i, j);
            cout << px << endl;
            if (px == pink){
                cout << "A" ;

            }
        }
    }

    waitKey(0);
    destroyAllWindows();
    return 0;
}
#包括“opencv2/highgui/highgui.hpp”
#包括
使用名称空间std;
使用名称空间cv;
int main(){
matem(100100,CV_8UC3,标量::all(0));
矩形(em,Rect(30,30,10,10),标量(147,20255),-1);
imshow(“em”,em);
等待键(1);
Vec3b粉红色(147,20255);
对于(int i=0;i如果每个通道都是8位通道,请使用.at(y,x)而不是.at(y,x)(这将是一个8位通道)。此外,将所有Vec3f更改为Vec3b。Vec3f意味着是3个浮动通道的像素。尝试将uchar替换为cv;;Vec3b.Vec3f px=em.at(y,x);3b和3f的区别是什么?@Mika我试着将uchar转换为Vec3b,当我打印px.val[0-2]时,输出是一些奇怪的符号,我可以问一下为什么吗?因为字符在打印时被解释为符号。如果可变像素是Vec3b,请尝试
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(){

    Mat em(100, 100, CV_8UC3, Scalar::all(0));
    rectangle(em, Rect(30, 30, 10, 10), Scalar(147, 20, 255), -1);

    imshow("em", em);
    waitKey(1);

    Vec3b pink(147,20,255);
    for (int i = 0; i < em.rows; i++){
        for (int j = 0; j < em.cols; j++){
            Vec3b px = em.at<Vec3b>(i, j);
            cout << px << endl;
            if (px == pink){
                cout << "A" ;

            }
        }
    }

    waitKey(0);
    destroyAllWindows();
    return 0;
}