1 | initial version |
cvtColor(src,img,CV_BGR2HSV); //convering src(RGB) to img(HSV)
Mat A(src.size(),src.type(),Scalar::all(0)); // creating a Matrix A of size src;
inRange(img,Scalar(170,155,150),Scalar(180,255,230),h1); //creating mask using inRange.
src.copyTo(out,h1); // copying src(RGB) image to out with mask;
This works for me Thanks @berak and @LBerger
2 | No.2 Revision |
I got it working
cvtColor(src,img,CV_BGR2HSV); //convering src(RGB) to img(HSV)img(HSV)
Mat A(src.size(),src.type(),Scalar::all(0)); // creating a Matrix A of size src;
inRange(img,Scalar(170,155,150),Scalar(180,255,230),h1); //creating mask using inRange.
src.copyTo(out,h1); // copying src(RGB) image to out with mask;
This works for me Thanks @berak and @LBerger
3 | No.3 Revision |
I got it working
cvtColor(src,img,CV_BGR2HSV); //convering src(RGB) to img(HSV)
Mat A(src.size(),src.type(),Scalar::all(0)); // creating a Matrix A of size src;
inRange(img,Scalar(170,155,150),Scalar(180,255,230),h1); //creating mask using inRange.
src.copyTo(out,h1); // copying src(RGB) image to out with mask;
This works for me Thanks @berak and @LBerger
4 | No.4 Revision |
I got it working
cvtColor(src,img,CV_BGR2HSV); //convering src(RGB) to img(HSV)
inRange(img,Scalar(170,155,150),Scalar(180,255,230),h1); //creating mask using inRange.
src.copyTo(out,h1); // copying src(RGB) image to out with mask;
This works for me Thanks @berak and and
cvtColor(src,img,CV_BGR2HSV);
Mat A(src.size(),src.type(),Scalar::all(0));
for (int i=0;i<img.rows;i++)
{
unsigned char *hsv=img.ptr(i);
unsigned char *dst=A.ptr(i);
for(int j=0;j<img.cols;j++)
{
unsigned char H=*hsv++;
unsigned char S=*hsv++;
unsigned char V=*hsv++;
if ( (H>170 && H<=179) && (S>155 && S<255) && (V>150 && V<230) ) {
*dst++ = H;
*dst++ = S;
*dst++ = V;
} else {
dst++;
dst++;
dst++;
}
}
}
cvtColor(A,out,CV_HSV2BGR);
this also works thanks @LBerger