Ask Your Question

diegomez_86's profile - activity

2015-10-07 03:49:27 -0600 asked a question Convert image from cv2 to cv to make a YAML file in python

Hello. I have an image loaded from cv2 (I cannot load it in cv directly because I have to use ROS on it and it just has conversion to cv2) and I need to convert it to cv in order to later write it as a YAML file. Does anyone know how to do it? I looked on internet for several options, but until now I see just how to write a YAML only from cv or how to load a YAML file in as an opencv Mat. I also found several help but in c++ (and I have to work on a python script)

If someone knows how to do it and can tell me the procedure, I would be very thankful to you guys.

2015-10-06 11:24:50 -0600 asked a question Saving an Opencv Mat into a YAML file using python

Hello, Does anyone know how to save, write, convert, etc an Opencv Mat into a YAML file using python?

I tried with cv.Save but it tells me "Cannot identify type of 'structPtr'", and with ImWrite it tells me error: "(-2) could not find a writer for the specified extension in function imwrite"

Thanks a lot for your help.

2015-06-15 18:06:19 -0600 commented question separating lab image into 3 components

Hi, and thanks. I already did it. and solved it with split as you said... Actually it was pretty easy. I didn't have to cope with all of those questions cause OpenCV did the job for me.

2015-06-14 05:43:12 -0600 asked a question separating lab image into 3 components

Hello Everyone, I want to dividide a BGR image into 3 images containing the 3 different CIE Lab color components (with just one channel). I know that I can do something like this:

 #include <opencv2/opencv.hpp>

 using namespace std;
 using namespace cv;

 int main( int argc, char** argv )
 {
      Mat src = imread( "/home/diego/Documents/sunset.jpg", -1 ), lab;
      cvtColor(src, lab, CV_BGR2Lab);
      imshow("lab", lab);
      return 0;
 }

And this gives me a kind of result like this

image description

However I read something that tells me that I need to treat the Luminance between 0 and 100, and a,b with values between -127 to 127 (So I don't know if this image is right or wrong). I would like to ask what is meant with these values... are these ones the pixel values, are these ones normalized values from the original 0 to 255? Are the values of this 3 channel image representing L((lab[0]), A(lab[1]), and B(lab[2])?

I have checked in several webpages to give me an idea but I just see very theoretical information about how the 3 axis Lab color space is composed but nothing that I can convert into real things.

Thanks and sorry for so many questions.

2015-06-13 14:21:48 -0600 commented answer show many images in different windows in a loop using one imshow command

I don't know if it worked for @zulfiqar to me it doesn't do it...

2015-06-09 11:56:20 -0600 asked a question 3d image reconstruction from a 2d image (a bottle pointing from 2d to 3d)

Hello Everyone

I am working on a spin the bottle game with OpenCV and a robot NAO. I already made a program to draw a line projecting to the pointing place of the bottle but in 2d (the robot can see just the bottle in a white background) now I would like with opencv to project that line into the 3d space in order to find a person which the bottle points to.

I am not sure how or where to start. I found something with camera calibration, Pose estimation and Depth Map from Stereo Images. Could you guys please help me with information or topics where I could start reading or doing something from OpenCV?

Thanks

2015-06-07 05:33:46 -0600 commented question Restric the angle of fitEllipse?

Hello, actually I am doing the orientation of a bottle and using fitEllipse for this... Could you please explain me what you mean with restrict the angle?... Perhaps I could help you :)

2015-06-06 09:11:34 -0600 commented answer creating a rotatedRect in a threshold image

Thanks @StevenPuttermans. Then I think I will keep converting the vectors to to Mat then.

2015-06-06 04:46:11 -0600 commented answer creating a rotatedRect in a threshold image

@theodore (or anyone who can answer this to me), I forgot to ask something about your code

In these 2 lines I saw that you converted the vectors of points into a matrices. Does it have any convenience for the program or does it produce better results? I tried with just the vectors of points pluse different images (20) and there was no difference (in the image, I don't know about the structure) in the results

 cv::convexHull(cv::Mat(merged_contour_points),hull);
 cv::RotatedRect minEllipse = fitEllipse(hull_points); //

Thanks in advance for your answer

2015-06-05 05:00:00 -0600 commented answer creating a rotatedRect in a threshold image

Wow, @theodore, Thanks for your help... it's awesome. Now I will look more at convex hull.

2015-06-04 16:33:43 -0600 asked a question 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

image description

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

image description

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.

image description

I also tried with contours, however the result is not also that good.

image description

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.

2015-06-03 08:34:20 -0600 received badge  Critic (source)
2015-06-01 03:28:55 -0600 answered a question Error showing values from an image in pixels with mouse callback

Hello and thanks to LBerger who made me take into account the row, columns thing. This is the final code:

 #include <iostream>
 #include <stdio.h>
 #include <opencv2/opencv.hpp>
 using namespace cv;
 using namespace std;

 Mat imageGreen;

 static void onMouse(int event, int x, int y, int f, void*){
cout <<(int)imageGreen.at<unsigned char>(y, x) << endl;
 }

 int main(int argc, char** argv) {
Mat inputImage = imread("/home/diego/Humanoids/imageGreen0.png");
imageGreen = Mat::zeros(inputImage.size(), CV_8UC1);

   //Getting the green channel value and putting it into a one channel value.

Vec3b result;

for (int i = 0; i < inputImage.rows ; i++)
{
    for (int j = 0; j < inputImage.cols ; j++)
    {
        result = inputImage.at<cv::Vec3b>(i,j);
        int value = result[1];
        imageGreen.at<uchar>(i, j) = value;
    }
}

cout <<imageGreen.channels()<<endl;

namedWindow( "imageGreen", CV_WINDOW_NORMAL);
imshow("imageGreen", imageGreen);
setMouseCallback("imageGreen", onMouse, 0);
waitKey(0);
return 0;

}

2015-05-30 10:27:46 -0600 commented answer Error showing values from an image in pixels with mouse callback

Thanks for showing me, however I need the green value sent into a 1 channel Uchar mat. I tried the way you told me and it worked, however I want just one single value and use this procedure in order to find a way of getting rid of the bottle shadow (I am assuming that the bottle is green ). but now that I want to check at the value, the screen just disappears. I updated the new code into the question.

Thanks for what I just learned and sorry for the inconvenient.

2015-05-30 10:00:43 -0600 received badge  Enthusiast
2015-05-29 18:37:52 -0600 asked a question Error showing values from an image in pixels with mouse callback

Hello, I want to check pixel values with this program, however the results are not convincing at all for me. I am loading an image in grayscale and the colors are of course very different as it can be seen in the image

image description

However when I pass the mouse (with the implemented mouse callback function) I receive white colors with values of 90 for example, or black colors with values of 130.

/*Updated algorithm. Now it doesn't show the values. the window disspaears like with an exception when the mouse is passed through the image"

#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <highgui.h>

using namespace cv;
using namespace std;

Mat image, imageGreen;
char window_name[20]="Get coordinates";

static void onMouse( int event, int x, int y, int f, void* )
{       
    uchar intensity = imageGreen.at<uchar>(x,y);
cout << "x: "<< x << " y: " << y << endl << " value: " << (int)intensity << endl;
}

int main() {
    namedWindow( window_name, CV_WINDOW_NORMAL );
    image = imread("/home/diego/Humanoids/imageGreen0.png");
    Mat imageGreen = Mat::zeros(image.size(), CV_8UC1);
    Vec3b result;

    for (int i = 0; i < image.rows ; i++)
{
    for (int j = 0; j < image.cols ; j++)
    {
        result = image.at<cv::Vec3b>(i,j);
        int value = result[1];
        imageGreen.at<uchar>(i, j) = value;
    }
}

    cout<< "Image depth: "<<imageGreen.depth()<<" # of channels: "<<imageGreen.channels()<<"\n";
    imshow( window_name, imageGreen );
    setMouseCallback( window_name, onMouse, 0 );
    waitKey(0);
    return 0;
}

I want to learn how to use this because I want to get rid of the bottle shadow (by the way, here I put the green value of each pixel from an RGB image into the correspondent pixel in a grayscale image --> It's a green bottle) and I thought that maybe there can be a difference between the values of the bottle and the reflection from the sun which can allow me to make a threshold.

Can anyone help me telling me what is the error here? I am trying to stop being a newbie in OpenCV and C++, but I think that there is still a long way for it. Thank you

I changed the algorithm and now I'm using another image

image description

2015-05-20 04:23:57 -0600 received badge  Scholar (source)
2015-05-20 04:23:51 -0600 commented answer How to make HoughlinesP to detect more lines?

You are awesome man. Thanks for the pre and post-processing ideas... I already used them on my program. Actually right now I'm just wanting to give an initial draft of the whole program (A Nao Robot playing spin the bottle game), later I will make more improvements and I will ask more from here.

2015-05-18 16:07:10 -0600 received badge  Student (source)
2015-05-18 08:37:07 -0600 commented question How to make HoughlinesP to detect more lines?

This is the code

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
 const char* filename = "/home/diego/Documents/frame0.jpg";

 Mat src = imread(filename, 0);

 Mat dst, cdst;
 Canny(src, dst, 100, 100, 3);
 cvtColor(dst, cdst, CV_GRAY2BGR);

  vector<Vec4i> lines;
  HoughLinesP(dst, lines, 1, CV_PI/180, 2, 50, 10 );
  for( size_t i = 0; i < lines.size(); i++ )
  {
    Vec4i l = lines[i];
    line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
  }

  imshow("original image", src);
  imshow("detected lines", cdst);

 waitKey();

 return 0;
}
2015-05-18 08:37:07 -0600 commented question How to make HoughlinesP to detect more lines?

Actually I am using CannyEdge + HoughLinesP

My idea is to find the orientation of the bottle. I tried with other options, actually there is an option to find the orientation of the bottle (Object orientation which appears in http://www.google.de/imgres?imgurl=ht...), however the shadow and reflect of the bottle affects the real orientation of it (So I would need to find an algorithm to detect them)

I will add the photos in my main question.

2015-05-18 05:05:40 -0600 asked a question How to make HoughlinesP to detect more lines?

Hello everyone, I am trying to detect the straight lines in a bottle. I am using the example provided by OpenCV tutorials however the maximum I can get is just one.

I have played with most of the parameters of CannyEdge and Houghlinesp, however the maximum I can get is always maximum 1 (I got 2 but just in one example) I am sending the examples of bottles that I am trying also with it's resulting example.

I have several suspects about the problems with this non-detection: one could be the shadow, other one could be the light reflect, and even I am thinking that the camera is not well calibrated. However if someone knows or has worked with this function before and thinks that this doesn't have any relation, I would thank you too much.

Thanks a lot for everything.

image description!

The original images

image description image description image description image description