Ask Your Question
0

masking green pixels - HSV

asked 2014-11-20 06:56:56 -0600

Hi friends,

I am working on a project detect leaf disease. Need help with implementation "masking green pixels" and set the threshold to get the mostly green color. So that way i can detect the disease ?

I've been looking up on google but still dont understand.

Thanks much

edit retag flag offensive close merge delete

Comments

This look close to your problem.

Haris gravatar imageHaris ( 2014-11-21 06:15:40 -0600 )edit

I also have same requirement, coding in python

SChatterjee gravatar imageSChatterjee ( 2019-06-27 01:51:53 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-11-21 04:57:33 -0600

Yesterday I was just working on this, here is my code, it works well for the green and blue on red but you can still do something

cv::Mat src = inputFrame;
if (src.empty())return -1;

if (m_currentView == kStageRedColor) {
    rangeH1 = 0;
    rangeS1 = 35;
    rangeV1 = 182;
    rangeH2 = 35;
    rangeS2 = 255;
    rangeV2 = 255;
}
else if (m_currentView == kStageBlueColor) {
    rangeH1 = 97;
    rangeS1 = 88;
    rangeV1 = 55;
    rangeH2 = 133;
    rangeS2 = 255;
    rangeV2 = 255;
}
else if (m_currentView == kStageGreenColor) {
    rangeH1 = 57;
    rangeS1 = 64;
    rangeV1 = 55;
    rangeH2 = 77;
    rangeS2 = 255;
    rangeV2 = 255;
}
else if (m_currentView == kStageManual) {
}


cv::Mat HSVsrc;
cvtColor(src,HSVsrc, cv::COLOR_BGR2HSV);
cv::inRange(HSVsrc, cv::Scalar(rangeH1,rangeS1,rangeV1), cv::Scalar(rangeH2,rangeS2,rangeV2), HSVsrc);

I hope that could help you , if you have information for the "red channel" please write to me ;)

edit flag offensive delete link more
0

answered 2014-11-20 08:11:10 -0600

You can use cv::cvtcolor to change the color space and then apply cv::inrange to the Hue-channel to create a mask.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-11-20 06:56:56 -0600

Seen: 1,592 times

Last updated: Nov 21 '14