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

时间:2016-01-11 06:57:02

标签: c++ opencv

这是我需要检测的图像

enter image description here

serverBootstrap.group(bossGroup, workerGroup).childHandler(new ChannelInitializer<SocketChannel>() {
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        ChannelPipeline channelPipeline = channel.pipeline();
        channelPipeline.addLast("String Encoder", new StringEncoder(CharsetUtil.UTF_8));
        channelPipeline.addLast("String Decoder", new StringDecoder(CharsetUtil.UTF_8));
    }
});

1 个答案:

答案 0 :(得分:0)

试试这段代码怎么样?

#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;
}