creating a rotatedRect in a threshold image
Hello everybody
I am trying to draw an ellipse based on some points that I assign from a Threshold in an image. This is the image
I used fitEllipse function with parameter, all of the points of all of the pixels in a vector of points, with this I thought I was going to get an ellipse in the center of the image, however I got this one
I would like to get something like this (of course it should be an ellipse, but I'm not an expert in graphical design with paint) in a way of ellipse or if it was possible to get a RotatedRect square like this, then it would be awesome too.
I also tried with contours, however the result is not also that good.
I would like your help guys. this is the code I am using
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
double thresholdValue = 0;
int main(int argc, char** argv) {
Mat src = imread( "/home/diego/Humanoids/imageGreen0.png", 1 );
Mat imageGreen = Mat::zeros(src.size(), CV_8UC1), threshold_output;
Vec3b result;
for (int i = 0; i < src.rows ; i++)
{
for (int j = 0; j < src.cols ; j++)
{
result = src.at<cv::Vec3b>(i,j);
int value = result[1];
imageGreen.at<uchar>(i, j) = value;
}
}
threshold( imageGreen, threshold_output, thresholdValue, 255, THRESH_BINARY_INV );
vector<Point2f> pointsPixels;
for(int i = 0; i < src.rows; i++)
for(int j = 0; j < src.cols; j++)
{
if((int)threshold_output.at<unsigned char>(i, j) == 255)
{
pointsPixels.push_back(Point(j,i));
}
}
RotatedRect elipseBottle = fitEllipse(pointsPixels);
ellipse(threshold_output, elipseBottle, Scalar(125), 2, 8 );
imshow("threshold ouput", threshold_output);
return 0;
}
I would be very thankful to you if you guys could help me with a solution or at least ideas (by now I will keep checking at rotatedRect functions or fitEllipse in case I did something wrong). Thanks a lot.