Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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# 获取具有相同颜色的所有像素坐标_C#_Image Processing_Opencv_Emgucv - Fatal编程技术网

C# 获取具有相同颜色的所有像素坐标

C# 获取具有相同颜色的所有像素坐标,c#,image-processing,opencv,emgucv,C#,Image Processing,Opencv,Emgucv,我想得到和一个像素颜色相同的所有像素坐标 List<cv::Point> GetAllPixels(cv::Point x) { //imp } 列出GetAllPixels(cv::Point x) { //小鬼 } 如何在EmguCV或OpenCV中执行此操作?下面是一个使用OpenCV C++的可能解决方案: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp>

我想得到和一个像素颜色相同的所有像素坐标

List<cv::Point> GetAllPixels(cv::Point x)
{
//imp
}
列出GetAllPixels(cv::Point x)
{
//小鬼
}

如何在EmguCV或OpenCV中执行此操作?

下面是一个使用OpenCV C++的可能解决方案:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace cv;

std::vector<cv::Point> getPixelsWithColor(const cv::Mat& src, cv::Scalar targetColor)
{
    assert(src.type() == CV_8UC3);

    std::vector<cv::Point> identicalPoints;

    for(int row = 0; row < src.rows; ++row)
    {
        for(int col = 0; col < src.cols; ++col)
        {
            cv::Vec3b currPixel = src.at<cv::Vec3b>(row, col);
            if(currPixel[0] == targetColor.val[0] &&
               currPixel[1] == targetColor.val[1] &&
               currPixel[2] == targetColor.val[2])
            {
                identicalPoints.push_back(cv::Point(col, row));
            }
        }
    }

    return identicalPoints;
}

int main(int argc, char** argv)
{
    Mat squares = imread("colored_squares.png");

    const Scalar RED = Scalar(0, 0, 255); // OpenCV is BGR order...
    vector<Point> redPixelLocations;
    redPixelLocations = getPixelsWithColor(squares, RED);

    Mat redMask = Mat::zeros(squares.size(), CV_8UC1);

    vector<Point>::iterator i;
    for(i = redPixelLocations.begin(); i != redPixelLocations.end(); ++i)
    {
        redMask.at<uchar>(*i) = 255;
    }

    imshow("Squares", squares);
    imshow("Red mask", redMask);
    waitKey();

    return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
std::vector getPixelsWithColor(常量cv::Mat&src,cv::Scalar targetColor)
{
断言(src.type()==CV_8UC3);
std::向量识别点;
对于(int row=0;row
我使用了这个输入图像:

并实现了此输出图像:


享受!:)

答案应该让你开始。同时考虑使用<代码> CMP < /代码>函数

对于
IplImage
,它可能是这样的:

IplImage *img, *col_img, *mask_img;
// initialise images appropriately...
svSet(col_img, [colour of your choise]);
cvCmp(img, col_img, mask_img, CV_CMP_EQ);
使用
mask\u img
提取坐标。您可以找到
cv::Mat
的等效操作