Ask Your Question

cpagravel's profile - activity

2017-03-27 11:17:07 -0600 commented answer Identify the best angle to orient a map

Thanks for the answer. I will probably do just that and make custom function. Cheers!

2017-03-22 19:25:23 -0600 received badge  Scholar (source)
2017-03-22 19:25:04 -0600 commented answer Identify the best angle to orient a map

I've been successful! Some pre-processing on the image helped with the Canny() double line problem. I did use bins and some statistical analysis, however I didn't find that I could specify a range when processing. Is it possible to limit the computations required by specifying a range for HoughLinesP?

2017-03-22 17:50:50 -0600 received badge  Supporter (source)
2017-03-21 13:07:12 -0600 commented answer I did the opencv installation instruction completely (in obunto 16, opencv 3.1.0(and 3.2)), but when i run a program, it encounter with problem

@berak No worries. @ashkan Glad to help.

2017-03-21 04:28:22 -0600 received badge  Student (source)
2017-03-20 22:12:17 -0600 commented answer Identify the best angle to orient a map

Thank you for the support. I've edited my question to reflect the new approach (I got rid of my old code to avoid clutter). I am getting results with HoughLinesP as you've suggested. The only part of your answer that I don't understand is how to set a range when I repeat the algorithm for a higher resolution. Are you suggesting just making a bounding box ROI over the lines I'm interested in an increasing the resolution? I don't see a HoughLinesP function that allows specifying a range.

2017-03-20 12:34:02 -0600 commented question How do I fix an undefined reference error while build opencv from source?

I can only give you a hint because I haven't looked at the CMake files. This is a linking error. The compiler will first compile all of your source code; when it's doing this it will use the header files (defined by the #include lines) to determine the functions available to a given source file. Any references to functions described in header files will then be left as empty pointers which the compiler will fill in during the linking stage of compilation (usually one of the last stages). This is why you see the error happen at the end.

The compiler is saying that there are functions in "../../lib/libopencv_cudalegacy.so.3.2.0" that have not yet been filled in.

So, somewhere in the CMake files there is a reference for building "../../bin/opencv_test_cudalegacy" which needs to be linked.

2017-03-20 12:07:01 -0600 commented answer I did the opencv installation instruction completely (in obunto 16, opencv 3.1.0(and 3.2)), but when i run a program, it encounter with problem

Can the downvoter please leave a comment? This is the correct answer. You need to use forward slashes for directory paths in Linux.

2017-03-20 12:04:43 -0600 received badge  Editor (source)
2017-03-20 12:03:59 -0600 answered a question I did the opencv installation instruction completely (in obunto 16, opencv 3.1.0(and 3.2)), but when i run a program, it encounter with problem

The issue is that the compiler cannot find "opencv.hpp". Since you're working on the Linux kernel, you need to use forward slashes for directories "/" instead of "\".

You have "opencv2\opencv.hpp" written instead of "opencv2/opencv.hpp". If you copied the code from somewhere, they were probably working on a Windows machine.

2017-03-20 11:05:54 -0600 commented answer Identify the best angle to orient a map

I've went through the tutorial of HoughLinesP and I was not getting very good results... The results I were getting indicate that my lines were not being detected where I believe that they should have been detected (i.e. from the middle of the line instead of from end to end). And not all lines were detected. You make a very good point though about using a broad detection phase first. I will try again and update and I will also take some time to earn some more reputation so I can add pictures.

2017-03-18 03:40:11 -0600 asked a question Identify the best angle to orient a map

This is the image I am working with: Robotics map

My goal is to rotate this (within a hundredth of a degree) so that the longest-lines/most-lines are completely horizontal.

First Attempts

The first thing I did was look into using Houghlines for this, but it doesn't help me find the "best" lines in my image. It just produces a set of lines and angles; this is a problem because there may be a lot of lines in my map and I need to know the length and angle of each of them to evaluate the best map orientation. After a lot of tinkering I wasn't able to get the function to properly detect precise location of my lines, even after giving rho and theta a precision of 0.01 and np.pi/18000 respectively.

My second attempt was to count the pixels individually and analyze them statistically. This was very computationally intensive and lead me down a rabbit hole trying to organise shared memory between multiple processors in Python. The original code is in the first version of my post (I've removed it to keep things clean).

Using HoughLinesP

As suggested I have tried using HoughLinesP.

import cv2                                                  # used for image processing functions
import numpy as np                                          # used for matrix calculations with opencv
class align_map():

  def __init__(self, map_name):
    image = cv2.imread(map_name)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    th, bw_image = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY)
    # cv2.imshow("bw_image", bw_image)
    edges = cv2.Canny(bw_image, 50, 150, apertureSize=7)

    threshold = 60
    min_line_length = 10
    max_line_gap = 30
    lines = cv2.HoughLinesP(edges, 1, np.pi/180, threshold=threshold, maxLineGap=max_line_gap, minLineLength=min_line_length)

    count = 50
    for x in range(0, len(lines)):
        for x1,y1,x2,y2 in lines[x]:
            cv2.line(image,(x1,y1),(x2,y2),(0,count,255-count),2)
            count = count + 20
            if (count > 255):
                count = 40

    cv2.imshow("HoughLinesP_Result", image)
    cv2.waitKey(0)

map_name = "example.png"
align_map(map_name)

HoughLinesP

I've managed to detect the lines reasonably well. The different colours are there just to identify individual lines

Now I need to sort these into respective bins according to their angle, but I have a slight problem because I am getting duplicates--you can see this by the red and green neighbouring lines. I believe this is because I'm using Canny() for my edge detection. It's a problem because it will skew my weightings for each line.

Canny Edge Detection