Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I'm looking for an extremely fast method to do getpixel.

I tried some methods but they where just not fast enough in combination with a live cam 120fps any suggestions ?

.., i'm beginning to wonder maybe it can only be done "live" if I go into assembler (which i rather do not, its been years ago that i did that, need to learn it again).. but speed is to slow even with lockbit images.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 20:40pm    
So, C++ or C# (maybe C++/CLI)?
--SA
enhzflep 27-Oct-12 1:29am    
Do you realize that 'extreme fast getpixel' and 'c#' is something of an oxymoron? What resolution is the video? 640x480 @ 24bit & 120Hz would be 120x640x480x3 = 105.5 Mb - a data rate not to be sneezed-at..
PGT 27-Oct-12 7:26am    
i fully understand, and there is my problem too
eventually i will even need faster camera's so 120fps is just a starter..
thats why i'm desperate for extreme fast code
enhzflep 27-Oct-12 8:12am    
Okay, sure - I'm desperate for a whole bunch of stuff. Sharing what and why often help facilitate those wishes and desires.

Perhaps if you could provide some more details of the project and it's intentions you'd also get answers that helped achieve your aims.

So, I'll go again. The answers to these questions still influence the approach taken.
1) What's the resolution and bit depth?
2) What's the format BBGGRR, RRGGBB, YUUVV, etc etc
3) What is the processing that needs to be done?

Questions 1 and 3 being the most important - perhaps in that order, perhaps not.
Obviously, processing the frame to remove it's chroma value (or saturation in the hsl model) will be a walk-in-the park compared to examining each frame for the presence of human faces. Similarly, motion detection will have a different processing requirement to one of de-skewing rotated images(video) of text.

So, if you could share these 2 or 3 figures we'll see if we can't help the search for an adequate solution.
PGT 27-Oct-12 8:45am    
well i didnt want to point people in certain directions at first, hoping for some new ideas, but i should have given that info your right, the image is RGB format , frame size 800x600 (its not usb based) and actually that's the low res mode.


And i've been thinking (i'm still in doubth) to do HSL, because that's more usable.
The processing is actually quite simple i need to detect and count how many dots are in a certain color range. (heu) So there is no facial detection or so, there are no shapes or 3d things, but on the backdraw i got to process every pixel, I cannt skip pixels. In contrast to face or 3d detection here the challenge is more basic while still though.

Hello,

For processing video on high rate you should use GPU.
You can use Direct3D and HLSL or OpenGL and GLSL for building effects or made some image processing. More complex things are available with CUDA and OpenCL.
For just blitting the data over CPU enougth will be DirectDraw or Direct3D.
For encoding better to use DXVA2 or CUDA or OpenMP plus usefull will be Intel's parallel studio and it related stuff for parallel data processing with high performance. Also helpful will be reading abt SIMD.

Regards,
Maxim.
 
Share this answer
 
Comments
PGT 27-Oct-12 12:18pm    
hm there's tons of information in there thanks.
is there a route that you would recommend me? (since there all new to me I got lots to learn)
Maxim Kartavenkov 27-Oct-12 12:30pm    
Forgot to mention that GDI+ also allows to modify the image:
http://www.c-sharpcorner.com/UploadFile/mahesh/Transformations0512192005050129AM/Transformations05.aspx
Here is some additional information:
http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/an-introduction-to-digital-image-processing-r2007
Once you download CUDA Toolkit in there you can find some samples of image processing.
Maxim.
Maxim Kartavenkov 27-Oct-12 12:20pm    
That's all depends on what for you need getpixel.
PGT 27-Oct-12 15:03pm    
i need it to fastly count certain pixels that fall into a heu range (or RGB with a work around). needles to say each frame is a new picture and a new count
Maxim Kartavenkov 28-Oct-12 2:08am    
For that you can use shaders, OpenCL, CUDA or OpenMP
If you really want GetPixel/SetPixel, it can only be in the cases where you need only few pixels, and then speed does not matter. If you need to copy or modify many pixels, the whole idea makes no sense. And you won't be able to do it fast anyway, no matter how hard you try. The approach is different: you need to pin a memory for a whole array of data at once and use it through pointers (unsafe code) or array indexing for massive operations. In this case, average access time per pixel can be quite small, which is all you need.

Now, you did not explain what imaging library do you want to use. Usually, you use either System.Drawing, which is used with System.Windows.Forms or just bitmaps, or, alternatively, you use WPF. It could be something else, not from Microsoft, available on all or some platforms. You should always tag such things when asking questions.

For Forms, you would need to use, BitmapLockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

For WPF, you can use System.Windows.Media.Imaging.BitmapImage. If you need to write bitmap, you would need to use
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx#inheritanceContinued[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[^].

You should better not mix System.Drawing with WPF, but, if it's absolutely necessary, there is an interop library:
http://msdn.microsoft.com/en-us/library/ms608869.aspx[^].

I would not recommend to go into interop; it's much better to choose one of the alternatives.

—SA
 
Share this answer
 
v2
Comments
PGT 27-Oct-12 7:31am    
yeah i know getpixel/setpixel wont do the job i need fast direct access, maybe even multi-threaded so each thread does a part of the frame.. (but that gives some overhead too creating a multi threaded app).. or perhaps launch is frame processing in its own thread.. i'm not really sure the only thing its got to be extreme fast.
And thats what wories me because i havent found it yet. here each milliseconds count for processing an image.
Sergey Alexandrovich Kryukov 27-Oct-12 22:40pm    
Multi-threading won't help. I already answered. The whole GetPixel/SetPixel approach is wrong. If you need few pixels, time does not matter, if you need many, do it massively. Overall, in most application, few pixels are rarely needed, and massive read or write is typical. From my answer, you should know what to do. Still not sure?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900