Ask Your Question

Fadi Abu Raid's profile - activity

2017-08-20 23:24:41 -0500 answered a question OpenCV CUDA - method that works like inRange()

As mentioned before "merge creates a multi-channels image ". The right approach would be using gpu::bitwise_and() function twice on the three threshold channels to get a binary single channel. I faced the same problem and came across your post and I assume many will face the same problem since there is no gpu::inrange() function. Here is the code I have implemented.

gpu::GpuMat imgpu;
gpu::GpuMat hsv;
gpu::GpuMat shsv[3];
gpu::GpuMat thresc[3];
gpu::GpuMat temp;
gpu::GpuMat thres;

//Transform image to HSV
gpu::cvtColor(imggpu, hsv, COLOR_BGR2HSV);

//Split HSV 3 channels
gpu::split(hsv, shsv);

//Threshold HSV channels
gpu::threshold(shsv[0], thresc[0], 45, 90, THRESH_BINARY);
gpu::threshold(shsv[1], thresc[1], 100, 225, THRESH_BINARY);
gpu::threshold(shsv[2], thresc[2], 20, 225, THRESH_BINARY);

//Bitwise AND the channels
gpu::bitwise_and(thresc[0], thresc[1],temp);
gpu::bitwise_and(temp, thresc[2], thres);