I recommend using Probabilistic Hough Transform - void HoughLinesP(InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 )
vector<Vec2f> lines;

Now, lines contains the end points of the line segments detected by the Probabilistic Hough transform. If you want to know the length of the line segment (in pixels), you can calculate the distance between its end points.