Ask Your Question
0

Detect long wavy line in image text

asked 2018-09-21 11:59:54 -0600

Frostyfox gravatar image

Hi,

Is it possible to detect the longest wavy line in following images and remove it. The line can be in any place of the image

I tried to apply erosion to remove those lines but for different types of font it is not working. Is it possible to to detect all long line in picture and erode that alone ?

Tried this code to predict lines but cant able to do it

inputImage = cv2.imread("input.png")
inputImageGray = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(inputImageGray,150,200,apertureSize = 3)
minLineLength = 30
maxLineGap = 5
lines = cv2.HoughLinesP(edges,cv2.HOUGH_PROBABILISTIC, np.pi/180, 30, minLineLength,maxLineGap)
for x in range(0, len(lines)):
    for x1,y1,x2,y2 in lines[x]:
        #cv2.line(inputImage,(x1,y1),(x2,y2),(0,128,0),2, cv2.LINE_AA)
        pts = np.array([[x1, y1 ], [x2 , y2]], np.int32)
        cv2.polylines(inputImage, [pts], True, (0,255,0))

font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(inputImage,"Tracks Detected", (500, 250), font, 0.5, 255)
cv2.imshow("Trolley_Problem_Result", inputImage)
cv2.imshow('edge', edges)

image description

image description

image description

image description

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-22 02:52:24 -0600

berak gravatar image

updated 2018-09-22 10:54:41 -0600

maybe you should try to undo the distortion, before doing any further processing,

remapping would help a lot here, please have a look at the tutorial !

int main()
{
    Mat img = imread("captcha1.jpg");
    float phase = -0.8 * CV_PI;
    float omega = 2.0 * CV_PI / img.cols;
    float amp = 15;
    Mat_<Vec2f> proj(img.size());
    for (int y=0; y<img.rows; y++) {
        for (int x=0; x<img.cols; x++) {
            float u = 0; // todo, i'll lleave it to you !
            float v = sin(phase + float(x) * omega) * amp;
            proj(y,x) = Vec2f(float(x) + u, float(y) + v);
        }
    }
    Mat corr;
    cv::remap(img, corr, proj, cv::Mat(), INTER_LINEAR);
    imshow("in",img);
    imshow("out",corr);
    waitKey();
}

remapped

edit flag offensive delete link more

Comments

Hi, Thanks for the help. This is working fine for sin type of distortion how ever Images are coming with both sin and cos format is possible to detect which one to apply.Applying sin for cos will make the image worse

Frostyfox gravatar imageFrostyfox ( 2018-09-23 02:01:59 -0600 )edit

sin and cos are only PI/2 apart. it's simply a phase problem.

(but ofc. there's also the same kind of distortion on the x-axis (not handled here))

berak gravatar imageberak ( 2018-09-24 05:51:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-21 11:59:54 -0600

Seen: 615 times

Last updated: Sep 22 '18