Ask Your Question

rocksean30's profile - activity

2016-01-18 11:02:21 -0500 asked a question Detect and extend white lines in an image.

Hello,

I have an image with white lines in it and I just need a program to extend those white lines C:\fakepath\vlcsnap.png Please guest me what should I do.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int thresh = 100;
Mat dst, cdst;
Mat img, original;

Mat whiteFilter(const Mat& src)
{
    assert(src.type() == CV_8UC3);

    Mat whiteOnly;
    inRange(src, Scalar(150, 150, 150), Scalar(255, 255, 255), whiteOnly);

    return whiteOnly;
}

void on_trackbar(int, void*)
{//This function gets called whenever a
    // trackbar position is changed

    Mat whiteOnly = whiteFilter(original);
    img = original.clone();

    Canny(whiteOnly, dst, 50, 200, 3);
    cvtColor(dst, cdst, CV_GRAY2BGR);

    vector<Vec2f> lines;
    HoughLines(dst, lines, 1, CV_PI / 180, thresh, 0, 0);

    for (size_t i = 0; i < lines.size(); i++)
    {
        float rho = lines[i][0], theta = lines[i][1];
        Point pt1, pt2;
        double a = cos(theta), b = sin(theta);
        double x0 = a*rho, y0 = b*rho;
        pt1.x = cvRound(x0 + 1000 * (-b));
        pt1.y = cvRound(y0 + 1000 * (a));
        pt2.x = cvRound(x0 - 1000 * (-b));
        pt2.y = cvRound(y0 - 1000 * (a));
        line(img, pt1, pt2, Scalar(255, 255, 255), 1, CV_AA);
    }

    imshow("detected lines", img);

}

int main(int argc, char** argv)
{
    Mat input = imread("D:/Pictures/vlcsnap.png");
    if (input.empty())
    {
        cout << "File not found" << endl;
        return 0;
    }

    img = input.clone();
    original = input.clone();

    imshow("input", input);

    Mat whiteOnly = whiteFilter(input);

    imshow("whiteOnly", whiteOnly);

    Canny(whiteOnly, dst, 50, 200, 3);
    cvtColor(dst, cdst, CV_GRAY2BGR);

    imshow("detected lines", img);

    createTrackbar("thresh", "detected lines", &thresh, 200, on_trackbar);
    waitKey();

    return 0;
}

The result I'm getting is not what i desire please help me.

Result C:\fakepath\white.png C:\fakepath\detected.png

2014-09-28 02:45:00 -0500 answered a question capture image to slow with java

Try lower resolution

VideoCapture capture = new VideoCapture(0);
int WIDTH = 320;
int HEIGHT = 240;
if (capture.isOpened())
{
    // to get the actual width of the camera
    System.out.print("Width: " + capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
    // to get the actual height of the camera
    System.out.println(", Height: " + capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));

    boolean wset = capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, WIDTH);
    boolean hset = capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
    if (!hset || !wset)
    {
        System.out.println("Width Changed: "+wset);
        System.out.println("Height Changed: "+hset);

        // to get the actual width of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
        // to get the actual height of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));
    }
}
2014-09-25 13:12:37 -0500 received badge  Editor (source)
2014-09-25 13:11:48 -0500 answered a question which class can show an image in java?

OpenCV java wrapper doesn't include Iamshow class But I found someone who posted this Iamshow class, I didn't try it yet you may try it yourself and update me too...

Also try this link I found it useful.