Wait at the Right Time


https://behappy.me/generator

For every course a student takes, it always starts with the basics. Our first topic in the laboratory was an introduction of the course and the basics of OpenCV - a C++ library that we will be using the whole semester for digital image processing. As I said the on my previous post, an image is represented as a two-dimensional array of pixels and per pixel has its corresponding values. Furthermore, it is said that a pixel's values represents the three (3) color channels - red, green, and blue. Each value determines the amount of a certain color channel is in that particular pixel. Usually the color channels are in the following order: red, green, and blue but in OpenCV, it is ordered in blue, green, and red.

In C++, as long as OpenCV library is importedan image can be stored in a container called Mat. 
For image reading, imread() function can be used. Other functions such as imshow()  and imwrite() are introduced.  imshow() shows the image selected while a program is running while imwrite() saves the image produced or selected with a new filename. We were also taught how to manipulate a pixel's color channels. The idea in manipulating all of the pixels in an image is to traverse every pixel in a row first then tweak the values of the pixel in each color channels until the last pixel of the last row of the given image.

After a few minutes of discussion, an exercise was given to test out if we understood something. The exercise is about transforming one image into another image in ten (10) different frames. We were given two images. 




And the output of the exercise was supposed to be like this:

https://imgflip.com/images-to-gif

The idea is the all of the pixels of the second image must be subtracted from the first image. This value is then divided into ten (10) because the exercise specifies that it needs to produce ten (10) frames. Then, update the image by either adding or subtracting the value that was produced before and repeat the process until all ten (10) frames are produced.

Doing this exercise was frustrating not because of the complicated algorithm behind the exercise (because it isn't complicated at all) but because of a misplacement of a waitkey() function. Figuring out what was the problem of my code ate up most of my time. Supposedly,  waitkey() is followed after imshow() for my exercise to work. With the help of my laboratory professor, he helped me where to put the waitkey() hence, I finished the exercise in time! The lesson is to wait at the right time. 😂

I'm planning to apply this simple image manipulation with some of the images I have on my laptop once I install and corporate OpenCV with DevC++ or when I have the free time on our laboratory. Once I get to do that, I'll post it on this blog! 'Til next time!


Comments