View Single Post
  #13   Spotlight this post!  
Unread 11-10-2014, 19:29
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Vision: what's state of the art in FRC?

Quote:
Originally Posted by faust1706 View Post
It can be inefficient, but it great at what it does. It is an open source library that people volunteer their time to contribute to. I think I'm going to be able to get away with taking 6 credit hours next semester for doing research in the field of computer science. That means I'll have dedicated time to work on stuff, like optimizing the opencv library (or just the functions I use regularly, such as erode, dilate, find contours, appoxpoly, solvepnp, and optical flow)

I've still not looked at the source code for opencv in depth. I really hope some things in it aren't parallel-ly computed because I love doing parallel computing and it'd give me great practice.

Like you mentioned...2 months ago to me, it spawns threads when it'd be quicker not to do it. Maybe I could simple put a condition that if the image resolution < (x,y), then don't spawn another thread.
I've been working on a library extension for OpenCV that adds features (there's currently no vanilla way to rotate an image x number of degrees!). I am also going to use OpenMP to attempt to create extremely high-performance functions that utilize all cores on your system!

The nice thing about OpenMP is that if it is not available, everything will work properly. The function won't be multithreaded though!

OpenCV actually has three modes for threading, as I remember. OpenCV can use OpenMP and IntelTBB and disabled.

I guess that you could use C++11 threading to parallelly perform many simple tasks. It is quite cool how the threading can be done with lambdas:
PHP Code:
std::thread x([](){printf("Hello World, from a thread :D");}); 
or using regular function pointers:

PHP Code:
void hello()
{
    
printf("Hello World, from a thread :D");
    return;
}

int main()
{
    
std::thread x(hello);
    
x.join(); //We're not doing anything new afterwards, so the thread would crash if we did not join it!

Instead of just skipping threading, better threading techniques should be used! Let's say cvtColor:
If the res is less than 32 by 32 (let's just say), then skip threading. This resolution should be quite low because threading is actually incredibly fast! Use libraries like pthread because of their speed. News Flash: C++11 threading under POSIX uses pthread .
What I would do is use divide the image up into equal parts, with the denominator as the hardware concurrency. I would then run my own version of cvtColor with no optimizations on that small image. Afterwards, I would stitch those images back together to return. Voilla! You have a cvtColor function that is highly optimized using your hardware concurrency. This really dictates how many threads the computer can run TRULY parallelly (not switching back and forth in threads!).

I believe the DLib has some optimized color conversion code too. Just convert the Mat to cv_image and it should work beautifully:
dlib::cv_image<dlib::bgr_pixel> image(cv::imread("image.png"));

Good luck! Maybe we can work on this stuff together!

-------------

As Lineskier mentioned, OpenCV is kind of difficult to get started with!
This is true. OpenCV is quite difficult to set up and start running. However, once the setup is complete, it is an extremely easy-to-learn library, especially because of it's documentation. There's a 600 page manual hat explains nearly every function. Just use [CTRL/CMD] + [F] and you should be good
However, I faced these chalenges with OpenCV, so I have a working install script that downloads my code and everything. Feel free to use the script under Debian/GNU Linux. If you don't want my old code, just remove those lines. I might remove them myself as they download a lot of code and fill up your drive!

If you want, Go ahead and check out my GitHub (@yash101)! I have all sorts of OpenCV programs!

install script:
PHP Code:
wget https://gist.github.com/yash101/10190427/raw/2926009fcf9cb0278d523a0e374d760dbbb92bcd/install.sh && chmod +x install.sh && ./install.sh 
Also, i spent around 3 hours a day during build season last year with OpenCV as I was learning it and coding with it at the same time. I also hadn't coded in C++ in 4 years so I lost all my good coding skills and had to recode the entire app a couple times. I at least got rid of the 1500 lines of code in int main() !

I am also working on the DevServer, which hopefully should make it much less of a hassle of granting the cRIO with data!

Last edited by yash101 : 11-10-2014 at 19:40.