Wednesday, November 21, 2007

Week 5 (19 Nov - 23 Nov)

Monday, 19 November 2007

Well, I returned to the office to play with the edge blending code completed last week and to my surprise, there is a secret memory leak in the program. Which is strange, because I had already done quite a few rounds of code walk-through and double-checking if I had freed all the pointers that are used in the process of the program. Well, except for two, which are used as function parameters. And when I released them when the function was done, the memory leak disappeared - which lead me to think, are declaring pointers in the function's parameters also creating new pointers in the system? Weren't they just used as a name or unique identifier within the method and not actual pointers? hmmm..

Anyway, with edge blending more or less done, it was time to move on to read up on on circle detection, and some code which I downloaded of the OpenCV Yahoo! Groups. Quite an interesting read, should be fun to implement.

We also went down to Beyond Social Service, a charity cum social home for unfortunate children who are faced with family issues that are beyond their control. We collected cards that asked them what they wanted for X'mas as well as their ambition when they grew up. IHPC is having a charity event on 18 December for these children. Kevin has roped us in to do a game station. JL and my station will definitely be an interesting one :)




Tuesday, 20 November 2007

Well, perhaps not as interesting as I had thought - still trying to understand the code from the Yahoo! Groups and reading up on the various methods used within the code, such as the CvBox2D and CvFindContours. The documentation is pretty abstract and I believe implicitly assumes that the developer already has background in this area of image/object recognition.

But nevertheless, today is spent more on reading and understanding and trying out.

To summarize today's post, the reason why I am researching on this circle/shape detection is because we are hoping to convert lightdraw into a POC multi-player real-time game where interaction between the various players and the computer takes place in a form of light trails. Hopefully it works :)



Wednesday, 21 November 2007

Yea! Manage to get the code working. Or at least to a certain extent. Had ported my mini-sandbox over to the actual project and it works, though a bit too well for its own good. Now, even curved straight lines are detected as a circle and some circles which end prematurely are not detected as circles. I spent the better half of the day playing around with the variables and adding an additional cvDilate to smoothen out the light outline - but the cvFindContour method does not seem to corporate and gives strange results.

Later in the day, was researching more about circle/shape detection and quite a number of sites mentioned about Hough transformation and how useful it is in helping the program use predefined points to conclude if the image shape that it takes in is that of a circle/square/cross, etc.

Not too sure on how it should work. Perhaps tomorrow will be another reading up day. :)



Thursday, 22 November 2007

We started off the day with the morning at the library as there was a teleconference going on in the Cove. We updated our journal and were tasked to help with IHPC's D&D gift wrapping. It was pretty interesting to help out in some of their various activities and along the way, I learnt how to tie a ribbon. :)

Back to lunch, then to work. Had a nice lunch at Business school canteen, generously sponsored by Kevin, our cool supervisor in IHPC. Worked a bit more on the circle detection and improved the code. Initially, the code based the circle on two points - the starting and ending - along the edge of the contour and decided if their distance was close enough to be considered a fully closed shape, which a circle is then drawn around it. This was under the assumption that the two points obtained would be of the starting and ending. However, the OpenCV library does it in such a way that the last point of the array is actually a random point close to the starting - making it hard to decide for which contour is a closed shape, and for which, isn't.

Thus I experimented a while here and there and discovered a more accurate algorithm. Well, I won't say its the best, and I'm open to feedback on better ones :). Here goes nothing - what the program now does is that it takes two sets of points on the opposite side of the contour and calculate the distance between the two points. A circle, give and take, will return two distances which are quite close (within 20 units difference). Another non-circle shape, such as a large oval or broken circle, will result in the distances being rather far apart (more than 20 units away).

And on some circles which are not properly captured by the camera, the two distances between the circle can be compared with the diameter of the circle which the program wants to draw onto the screen. If any of the distances are quite close, the circle is drawn, else not.

I have not actually implemented the code onto the C file yet, as I had taken over JL's combined code on edge blending and trailing to see if I can make it more OO and check for any errors such as pointers left behind. Well, I double checked the program and removed all the pointers. However, a memory leak still occurs. After mistaking "size + 1" as the size variable incrementing by 1, I decided to call it a day. We finally left the office at 6.45pm.



Friday, 23 November 2007

My life revolves around circles, or so it seems - circle detection for the whole week now. When I try to recall what I ate yesterday for lunch, or what date was it on Monday, I cannot seem to recall. Everyday seems to have new things to do, new challenges to overcome that it feels that time just flies by. *flies*

Anyway, I've increased the number of point pairs to 3 (6 points in total) , and the average of these three compared to the circle computed for increased accuracy. Pretty okay, just that when some circles are not really complete circles, but nevertheless are still circles, the software does not detect them.

Maybe I shall post up a few pics of the circle detection some other time. Anyway, today is dinner and dance for the company, hope everyone enjoys themselves with all the games, prizes and dinner.



Reflection for the Week:

Lightdraw seems to be making healthy progress for a month now, in my humble opinion. However, there are lots of other things to be done to improve the software. Trailing and edge blending have been integrated into a single file and we have swapped our gcc compiler to a gpp compiler on Tuesday to make use of data structures such as queues as C does not support it.

With circle detection more or less there, the next step would be collision detection with rendered shapes on the screen. The POC game which involves multiple players playing simultaneously and interactively on an improved piece of lightdraw code will hopefully be something achievable within the next week.

Other than that, I'm beginning to get more or less used to the traveling to work each day and even found an alternative route to work in the event I miss the bus I usually take one street away. However, I will not get ample sleep on both bus journeys as they are rather short to sleep on. Since the time spent on traveling each day to work and back home is long, I've learnt to make use of my time at work better, trying to spend my time there productively so that not a day goes by in waste. Hopefully, we can finish the project faster too, with some cool new add-ons.

Last thing I've learn this week from various incidents - email is a voiceless and toneless medium of communication via plain text. Words are taken at face value unless elaborated, so I must remember to choose wisely, or elaborate more. :)

No comments: