Reputation: 29
So I have this image: Cross
It looks like a small image, but actually it comes from a camera with a large resolution, which means the matrix of this image will be of large dimensions.
What I need to do is to find the cross in the fastest way possible.
I tried to scan all of the matrix and find where the white lines are but I'd like to hear from you maybe you have better and faster solutions for this problem.
Keep in mind that this image comes from a camera so this may look like a regular case but in reality a lot of stuff can happen, like cross not in the center, cross moves etc.
Thank you very much and have a good day.
--Edition--
I am sorry for not answering the questions. I am a student and unfortunately my schedule is crazy.. I will try my best to be online.
The answers to your questions are:
What is the full size of the original image? Maximum image size is: Width: 1936 px, Height: 1216 px. However, since we design the program for users, the user can manage the resolution as he/she pleases.
What OS are you using? Windows 7/8/10
What language/toolset? I am writing in C#. I was given an API of a camera and I need to use this API in order to make calculations regarding the image I get from the camera.
Have you got a GPU? I think so..
Multi-core CPU? Umm.. I don't think so..
How do the last two questions relate to my question? I am asking because I am new to this..
Another questions asked:
+ Since the position of the cross is user defined, it can be wherever on the screen. It can also not show up at all, since the user can forget to open up the camera or whatever.. So basically, anything can happen.
In addition, the camera itself maybe broken or not perfect and some unexpected things may appear on the screen like random white pixels or stuff like that.
+ About the minimum width of the cross lines - I actually don't know.. It comes from a camera so it's basically light. I depends on the users and what device they are using. So I guess the minimum is 1 px in that case.
What I mean by "finding the cross" is:
I need to find the center of the cross in the image in the fastest way possible, just like a measuring device.
Right now the algorithm is scanning the matrix of the pixels given by the picture on the screen and finding the maximum value in the row, per each row.
Then, calculating where it is and doing some math with it..
But the point itself is to get the position of the center of the cross in the fastest way possible while keeping the accuracy of the calculation.
We don't want to lose data since the program can be used in a very sensitive environment..
I hope I made things clearer..
Again, sorry for the delay and thank you for your help.
Upvotes: 1
Views: 116
Reputation: 207465
Updated Answer
The question about your CPU being multi-core (and having a GPU) is critical - it's not good enough not to know.
If your camera takes 50ms to acquire an image and you do no processing, you can do 20 frames a second.
If you spend 50ms acquiring a frame and then 50ms processing it, you can now only do 10 frames a second.
However, if you have a multi-core CPU and write multi-threaded code, you can acquire a frame in 50ms and have, say each of 3 other threads/cores doing 50ms of processing before the next frame comes, so suddenly you can do 150ms of extra processing per frame and still keep up the frame rate you achieved with no processing at all.
The above also applies to your GPU.
Have a look at the red/green graph at the bottom of my other answer here to better understand what I am saying about threads.
Also, the type of operations summing up across frames lends itself very much to SIMD optimisations, so you need to make sure your compiler is set to optimise/vectorize sequential memory accesses - or hand-code SIMD versions.
Original Answer
You could try resizing/summing across the image to a tall column, 1 pixel wide. And then likewise down the image to a long bar 1 pixel high. Then look for a maximum (or centre) of the corresponding white bars:
I have shown the bars 10 pixels wide here so you can see them.
Upvotes: 0
Reputation: 127
Image processing is expensive computationally. Focusing on quality, based on the example you gave, the first thing you should consider is applying a high-pass filtering over the image. It will make it easier to find the cross and harder to fall on a wrong detection. If you're looking for a good reference there is a book called "Digital Image Processing" from Rafael Gonzalez that cover basically everything you will need to know.
Upvotes: 0
Reputation: 80187
All depends on real image quality. For given example it is enough to find the brightest pixel in every line and column and build least-squares approximations for lines, or calculate image moments
If there are arbitrary objects and some noise presents, one could try Hough transform to determine lines
Upvotes: 1