The project / HowToBuild ? / ■ Samples page / History / Licence / Changes log
You can find here some sample on how to use Yayi. Emphasis is put on the Python and header uses. Most of the content here can be found in the unit and regression tests of the library (both in Python and C++).
Some manipulations are needed in order to get everything work well. Emphasis is currently put on the Python part, but C++ details will follow soon.
Yayi depends on several (but not so much) other libraries, and in that extent, you should - in most cases but not always - properly set up the environment before launching Python. This is basically done by following the same instructions as for launching the unit and regression tests of Yayi. Suppose your distribution of Boost is installed in $BOOST_ROOT_DIRECTORY, the Boost binary libraries normally are in $BOOST_ROOT_DIRECTORY/lib. You should tell the system to look for the Boost dependencies in this location.
On Linux machines:
On MacOS X:
On Windows, the easiest thing is to copy the Boost dynamic libraries into the same directory as the output of Yayi. In a console, you can also set up the PATH variable:
In order to be able to load Yayi libraries, Python should be informed about their location. Suppose now your Yayi binaries are put into YAYI_OUTPUT_DIRECTORY. Then a Python session typically begins with:
import sys
sys.path.append(YAYI_OUTPUT_DIRECTORY)
By default, YAYI_OUTPUT_DIRECTORY points to "Yayi/../Tmp/YAYI_SVNXXX/", where XXX is the SVN version of the release but it can be changed during the cmake configuration. Please refer to the building page for more information.
This example prints the current version of Yayi, then reads a JPG file into an image object. The image is then transformed into the HLS (L1) representation. The luma channel is copied into another image, with is then saved back to a PNG file.
This example shows the ease for writing simple Python code with Yayi (the code is exaggeratedly detailed).
# Loads the common library import YayiCommonPython as YACOM # Prints the current version print 'Current build version is', YACOM.current_build_version() # Loads the image library containing the image definitions import YayiImageCorePython as YACORE # Loads the image I/O library import YayiIOPython as YAIO # Reads file "my_jpeg_file.jpg" into "im" im = YAIO.readJPG("my_jpeg_file.jpg") # Prints the properties of "im" (geometry, pixel type, ...) print im # Creates an image similar to "im", but with type "float of 3 channels" im_hls = YACORE.GetSameImageOf(im, YACOM.type(YACOM.c_3, YACOM.s_float)) # Loads the pixel processing library import YayiPixelProcessingPython as YAPIX # Converts "im" (by default RGB) into "HLS L1" representation YAPIX.RGB_to_HLS_l1(im, im_hls) # Creates an image similar to "im_hls", but of one channel only im_grey = YACORE.GetSameImageOf(im_hls, YACOM.type(YACOM.c_scalar, YACOM.s_float)) # Copy the content of the second channel of im_hls (luminosity "l") into im_grey YAPIX.CopyOneChannel(im_hls, 1, im_grey) # Creates an image similar to "im_grey", but of type 8 bits unsigned im_grey_8 = YACORE.GetSameImageOf(im, YACOM.type(YACOM.c_scalar, YACOM.s_ui8)) # Multiplies im_grey (in the range [0, 1]) by 255, and puts the result into im_grey_8 YAPIX.MultiplyConstant(im_grey, 255, im_grey_8) # Writes "im_grey_8" into the file 'out_channel_lum.png' YAIO.writePNG("out_channel_lum.png", im_grey_8)
#include <Yayi/core/yayiCommon/include/current_configuration.hpp> void function1() { // outputs the current Yayi version std::cout << yayi::current_build_version() << std::endl; // to be completed ... }