Ask Your Question

Delgan's profile - activity

2018-02-07 11:08:40 -0600 received badge  Supporter (source)
2018-02-07 11:08:37 -0600 marked best answer Does modifying ROI of an image will also impact the image itself?

Hello.

I have code which looks like this:

cv::Mat image = getImage();  // CV_32FC3
cv::Rect roi = getROI();

if (condition1) {
    cv::Mat part;

    if (condition2) {
        part = image;
    } else {
        part = image(roi);
    }

    // This sometimes evaluates as 'false' and raises an exception
    assert(part.data == image.data);

    // This is expected to also impact the 'image' matrice
    cv::addWeighted(part, 0.5, getMask(), 0.5, 0.0, part);
}

// [...] Continue modifying 'image'

Basically, I want to modify a "global" image based on a first condition1. Then, according to the condition2, I need to modify the image partially or entirely.

Can I expect this code to work in all cases (removing the assert statement)? That is, that the modification applied to part will also be visible on image.

I have doubts because of the assert that sometimes is true and sometimes is false (with the ROI). I imagine that under certain conditions, the pointer part.data can designate a address with some offset compared to image.data, that is why the assertion fails (but still, there is image.data + offset == part.data)?

2018-02-07 11:08:37 -0600 received badge  Scholar (source)
2018-02-07 08:35:57 -0600 asked a question Does modifying ROI of an image will also impact the image itself?

Does modifying ROI of an image will also impact the image itself? Hello. I have code which looks like this: cv::Mat im

2015-10-18 04:26:01 -0600 asked a question Trouble with detecting color from HSV image using OpenCV and Python

I am trying to perform a simple colored object detection using OpenCV and Python.

I have read several tutorials but I encounter a confusing problem that prevents me to progress. Although I provide correct data HSV, my program does not seem to detect objects of that color.

I use this image (sorry for the poor quality of my webcam):

Sample

In order to detect the red object, I recovered the HSV color data:

Color data

And here is my code:

YELLOW = 30
BLUE = 210
GREEN = 145
RED = 320

color = RED

img = cv2.imread("sample.png")

hue = color // 2

lower_range = np.array([max(0, hue - 10), 0, 0], dtype=np.uint8)
upper_range = np.array([min(180, hue + 10), 255, 255], dtype=np.uint8)

img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

mask = cv2.inRange(img, lower_range, upper_range)

binary_img = cv2.bitwise_and(img_hsv, img_hsv, mask=mask)
binary_img = cv2.cvtColor(binary_img, cv2.COLOR_BGR2GRAY)
_, binary_img = cv2.threshold(binary_img, 127, 255, cv2.THRESH_BINARY)

cv2.imshow('sample', binary_img)
cv2.waitKey(0)

Result:

Result

The result for others colors is correct (not perfect because of the poor quality I guess), but I can not get something for the red. Yet, the HSV converted image is quite explicit:

HSV Image

Do you see what am I doing wrong, please?