Roel Balink
Roel Balink

Reputation: 417

Find corner in line from image

In C# I'm trying to find the corner in an image. The image is taken with a Camera, so not every shot will be exactly the same.

The image taken with the camera looks like this:

original image

I've already succeeded in getting the top edge of the Dark/Light part. On this line I want to find the corner.

This is the array of data I have gotten from the image. The items in the array with 0 are the columns in the image where no Dark/Light edge was found:

int[] items = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 338, 336, 335, 335, 335, 334, 334, 334, 334, 334, 334, 334, 334, 333, 333, 333, 333, 332, 332, 332, 332, 332, 332, 332, 332, 331, 331, 331, 331, 331, 331, 331, 331, 330, 330, 329, 329, 329, 328, 328, 327, 327, 326, 326, 326, 325, 325, 325, 325, 325, 324, 324, 324, 324, 324, 324, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 318, 318, 318, 318, 318, 318, 318, 318, 318, 317, 317, 317, 317, 317, 317, 317, 317, 316, 316, 316, 316, 316, 316, 315, 315, 315, 315, 315, 315, 314, 314, 314, 314, 314, 313, 313, 313, 313, 313, 313, 312, 312, 312, 312, 312, 311, 311, 311, 311, 311, 310, 310, 310, 310, 309, 309, 309, 309, 308, 308, 308, 308, 307, 307, 307, 307, 307, 306, 306, 306, 305, 305, 305, 305, 304, 304, 304, 304, 304, 303, 303, 303, 303, 302, 302, 302, 302, 301, 301, 301, 301, 300, 300, 300, 300, 299, 299, 299, 299, 299, 298, 298, 298, 298, 297, 297, 297, 297, 297, 296, 296, 296, 296, 296, 295, 295, 295, 295, 295, 294, 294, 294, 294, 293, 293, 293, 293, 293, 293, 292, 292, 292, 292, 292, 292, 291, 291, 291, 291, 291, 291, 291, 291, 290, 290, 290, 290, 290, 290, 290, 290, 290, 290, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 289, 290, 290, 290, 290, 290, 291, 291, 291, 292, 292, 293, 294, 294, 295, 295, 296, 297, 298, 299, 300, 300, 301, 302, 303, 304, 305, 306, 307, 308, 310, 311, 313, 315, 317, 320, 323, 327, 337, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

When placed in Excel this gives the following line: Excel graph

Now I'm looking for a decent way to find the corner point, I've already tried multiple things, but the difference in results from different images taken with camera of the same object differ to much. So I'm looking for a way to implement this better (probably there is an algorithm for this that I don't know about).

The point that I'm searching for is the location where the 2 red lines in the image below cross: Excel graph with drawn lines

How can I calculate/find those two red lines from the array I have?

Upvotes: 1

Views: 155

Answers (1)

MBo
MBo

Reputation: 80325

Apply thresholding to make image binary, extract border pixels, then use Hough transform to get straight lines and choose the most voted ones.

It would wise to use some imaging library like OpenCV or other one suitable for c#

Upvotes: 1

Related Questions