I’ve annotated some pictures and I want to find the coordinates of where the annotations occur. I want the coordinates of the pixel values of the pictures. I am new to Python/opencv and not sure what method I should look into.
The image above is an example of what my annotations would look like. My actual pictures have better resolution and have the same dimensions. I used the RBG value (255, 0, 0) to annotate my images. I want my program to return the coordinates into a column in an excel.
I’ve tried using the opencv subtract and absdiff methods but I don’t think it is doing what I need it to do.
You’re right about being wrong.
Look into:
inRange
findContours
moments
An example code is:
vector<glm::vec3> loop_centres;
vector<glm::vec3> loop_colours;
for (size_t i = 0; i < distinct_colours.size(); i++)
{
Mat mask;
inRange(input_light_mat,
Scalar(static_cast<unsigned char>(distinct_colours[i].r * 255.0f), static_cast<unsigned char>(distinct_colours[i].g * 255.0f), static_cast<unsigned char>(distinct_colours[i].b * 255.0f), 255),
Scalar(static_cast<unsigned char>(distinct_colours[i].r * 255.0f), static_cast<unsigned char>(distinct_colours[i].g * 255.0f), static_cast<unsigned char>(distinct_colours[i].b * 255.0f), 255),
mask);
vector<vector<Point> > loop_contours;
vector<Vec4i> loop_hierarchy;
findContours(mask, loop_contours, loop_hierarchy, RETR_LIST, CHAIN_APPROX_NONE);
for (size_t j = 0; j < loop_contours.size(); j++)
{
cv::Moments M = cv::moments(loop_contours[j]);
if (M.m00 == 0)
continue;
cv::Point2f loop_centre(M.m10 / M.m00, M.m01 / M.m00);
Vec4b pixelValue = input_light_mat.at<Vec4b>(loop_centre.y, loop_centre.x);
loop_centres.push_back(glm::vec3(loop_centre.x, loop_centre.y, 0));
loop_colours.push_back(glm::vec3(pixelValue[0] / 255.0f, pixelValue[1] / 255.0f, pixelValue[2] / 255.0f));
}
}
and what do you want to do with that information? beyond stuffing it in an excel file, of course.
the answer to that question determines what you actually need. it may not be coordinates that you need.
I am trying to do some image detection. So based on the annotated image, I want to get where the coordinates of object is in the original picture. I will use the numbers here for some other statistical analysis later on.
1 Like