sách gpt4 ai đã đi

opencv - OpenCV:检索轮廓中心的颜色

In lại 作者:行者123 更新时间:2023-12-02 17:51:31 27 4
mua khóa gpt4 Nike

我试图使用OpenCV检测黑色图像中一组形状的颜色,为此我使用了Canny检测。但是,颜色输出总是返回为黑色。

std::vector<> > Asteroids::DetectPoints(const cv::Mat &image)
{
cv::Mat imageGray;
cv::cvtColor( image, imageGray, CV_BGR2GRAY );
cv::threshold(imageGray, imageGray, 1, 255, cv::THRESH_BINARY);
cv::Mat canny_output;

std::vector<> > contours;
std::vector hierarchy;

int thresh = 10;
// Detect edges using canny
cv::Canny( imageGray, canny_output, thresh, thresh*2, 3 );
// Find contours
cv::findContours( canny_output, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cv::Point(0, 0) );

std::vector<> > points;

for(unsigned int i = 0; i < contours.size(); i++ )
{
cv::Rect rect = cv::boundingRect(contours[i]);
std::pair posColor;
posColor.first = cv::Point( rect.tl().x + (rect.size().width / 2), rect.tl().y + (rect.size().height / 2));

posColor.second = image.at( posColor.first.x, posColor.first.y );

//Dont add teh entry to the list if one with the same color and position is already pressent,
//The contour detection sometimes returns duplicates
bool isInList = false;
for(unsigned int j = 0; j < points.size(); j++)
if(points[j].first == posColor.first && points[j].second == posColor.second)
isInList = true;

if(!isInList)
points.push_back( posColor );
}
return points;
}

我知道位置或沿这些方向的东西一定是一个问题,但我不知道是什么

1 Câu trả lời

我可能是错的,但是浮现在脑海:

这不应该读

posColor.second = image.at(posColor.first.y, posColor.first.x);

而不是像你那样反过来吗?

矩阵符号,不是笛卡尔符号?

关于opencv - OpenCV:检索轮廓中心的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20303551/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com