projet_electronique_inra_2009.pdf

34
Elec4 Project - 2008/2009 Automatic Insect Monitoring Renaud GENSOLEN Guillaume LAUER Jonathan MOLON June 19, 2009 Internship mentor: Eric WAJNBERG Internship coordinator: Serge MILLON 1

Upload: shivam-jaiswal

Post on 15-Nov-2015

2 views

Category:

Documents


0 download

TRANSCRIPT

  • Elec4 Project - 2008/2009Automatic Insect Monitoring

    Renaud GENSOLENGuillaume LAUERJonathan MOLON

    June 19, 2009

    Internship mentor:Eric WAJNBERG

    Internship coordinator:Serge MILLON

    1

  • AcknowledgementFirst of all, we would express our gratitude to our internship mentor Mr Eric WAJNEBERG forhis welcoming at his INRAs workspace and all the explanations about the project he gave us.

    We also would like to acknowledge Mr Serge MILLON - our internship coordinator - for hisadvice and experience feedback.

    We thank Mr Vincent GRANET for his help in understanding some concepts we werent familiarwith.

    We finally give thanks to the NXP team for sharing their working room and their support.

    2

  • ContentsIntroduction 6

    1 Project overview 71.1 DC motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.2 Linear power amplifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3 End stops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.4 Incremental encoders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.5 Motor DC card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.6 Joystick card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.7 The camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.8 The computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    2 Project charter 92.1 Project title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3 Needs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.4 Sponsors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.5 Stakeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.6 Project manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.7 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.8 Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.9 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.10 Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    3 Acquisition 113.1 An appropriate library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Adaptation in Trajecto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 JNI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    4 JPEG/BMP 154.1 Bitmap Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    4.1.1 File header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.1.2 Bitmap informations headers . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.1.3 Color palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.1.4 Bitmap data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    4.2 JPEG Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.3 Considered solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    4.3.1 Work directly on the JPEG images pixels . . . . . . . . . . . . . . . . . . . . 174.3.2 Convert JPEG into bitmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.3.3 Find a solution with AXIS the suppliers of camera . . . . . . . . . . . . . . . 17

    5 Image processing 195.1 Issue source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.2 Size and definition of the BMP picture . . . . . . . . . . . . . . . . . . . . . . . . . . 195.3 Problem with the matrix size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.4 Conversion from 3 bpp to 1 bpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    3

  • Conclusion 23

    Appendix 24A Gantt Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24B Acquiring an image (C-source) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25C Acquiring an image (Java-source) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27D Jpeg2bmp.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29E Matlab: obtain the binary code of an image . . . . . . . . . . . . . . . . . . . . . . . 33F Get an image in Trajecto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    4

  • List of Figures1 Project environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Functions sequence acquiring an image . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    List of Tables1 Bitmap headers informations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    5

  • IntroductionThe INRA - Agricultural Research National Institute - works on wild insects behaviour. A researchin the Lab of Biology of Invertebrates at INRA Antibes is to realize biological insecticides usinguseful insects. Thus, to analyze their behavior, we must know their moving in various experimentalconditions. This experience requires a system performing and recording monitoring the movementof insects in various environments.

    Our work is to continue the work of previous student which was to develop an automaticmonitoring system of insects with a camera moving above the insect. This application will allowresearchers to perform statistics on wild insects movements.

    This project begin again this year because last year a few weeks before presentation, the acqui-sition card burned making the camera and the entire project unusable.

    The last team working on it and the coordinator chose to buy a camera working on IP network.So the new project was to suit this new camera with the software Trajecto for, then, being able todevelop the part where the camera dynamically follow insects.

    6

  • 1 Project overviewThe institute developed a device allowing the display of insect made by students in Polytech NiceSophia. This system consists of a camera which recorded the workplan and it connected to thenetwork. The result is observed on a PC which is connected to the network too. The camera ispositioned on two axes moving through a graphical user interface or a Joystick card . The camerafilmed the movement of an insect placed on the workplan. The image is then processed to get thetrajectory of an insect.

    Figure 1: Project environment

    The model is formed with several elements:

    1.1 DC motorsTwo DC motors are used to move the camera. These are connected to two worms located on twoorthogonal axes. The speed of these engines evolves according to the tension that we send frompower amplifiers.

    1.2 Linear power amplifiersThe voltage setting ranging from -10V to +10V is amplified to supply DC motors.

    1.3 End stopsThey are active if the camera is a stop on one of axes.

    1.4 Incremental encodersTwo incremental encoders were fixed on the DC motor and generate 500 pulses at every turn.

    7

  • Each contains two channels out of step about 90 degrees to know the meaning of displacementDC motors (see figure). These encoders will enable us to know the exact position of the cameraalong two axes in impulses or centimeters for the dynamic tracking of moving insects.

    1.5 Motor DC cardThis card is the link between the motors, encoders, end stops and the computer.

    It contains a pic microcontroller that provides transmission between the mechanical and com-puter via serial port and the enslavement of DC motors when moving the camera. Besides, it wastwo digital analog converters transforming the digital record of eight bits in a tension between -10Vand +10 V sent to the power amplifiers.

    1.6 Joystick cardThe joystick card can order DC motors through 4 push buttons and a button on / off managing bycontrol relay placed on the motor DC card. This card can function without the microcontroller inorder to move camera without the computer.

    1.7 The cameraThis camera is an Axis 211M working under IP network.

    1.8 The computerIt runs on the Linux operating system, it drives the system using the graphical interface programdeveloped in previous years: "Trajecto." It manages the movement of the camera but also treat theexperience made by the biologist.

    8

  • 2 Project charter

    2.1 Project titleThe title of this project is:

    Automatic Insect Monitoring

    His code name is: Trajecto.

    2.2 DescriptionDesigning a software using a camera working on IP network. This camera can:

    View the movement of the insect on a screen

    Follow the trajectory of an insect moving on a glass plate

    Control motors which permit to move the camera in two dimensions

    Automatically command motors to center insects in the center of the camera vue.

    Motors are controlled by a PIC18FXXXX powered by an external 5V power.

    2.3 NeedsObjectives are the study of a trajectory followed by an insect. It is a research project, so there isno industrial needs.

    2.4 Sponsors INRA represented by Mr Eric WAJNBERG.

    PolytechNice-Sophia represented by Mr Serge MILLON, co-responsible of elec4 projects.

    2.5 StakeholdersStakeholders are represented by the projects sponsor.

    2.6 Project managerMr Renaud GENSOLEN was designated as the project manager. Under the supervisition of theprojects sponsors, M. Renaud GENSOLEN has to bear, and got all powers to do, planning andbudgeting, monitoring, control and close the project.

    Mr Renaud GENSOLEN will be assisted by Messrs Guillaume LAUER and Jonathan MOLONto realize the project.

    2.7 ResourcesINRA provides a room equipped with a computer and in which we can install all the requiredequipment (camera, motors).

    PolytechNice-Sophia will provide us all required electronic equipments to test and programmingthe PIC.

    9

  • 2.8 DeliverablesThis project will get these deliverables:

    The software Trajecto.

    Datasheets.

    These deliverables concerning INRA - project sponsor. PolytechNice-Sophia, other sponsor, willdefine deliverables they waits for.

    2.9 ConstraintsThe project starts this year with a new camera working on IP network.

    The image flow must be around 20 images/second.

    2.10 PlanningAt the beginning of the project, we plan the differents objectives which we have to reach on thefirst Gantt (cf. appendix A-left).

    Then we have done a second Gantt with the differents problems we have met during this project(cf. appendix A-right).

    10

  • 3 AcquisitionThe software Trajecto works under Ubuntu - a Linux environment - with some additional libraries.So we decided to recreate Trajectos environment on our computers. Thus we were not oblige tomove each Friday to the INRAs lab. By the way, we could also work on it at home.

    Our team was finally ready to start this project !

    3.1 An appropriate libraryThe previous camera had an owner library which worked only with that camera and that acquisitioncard.

    In the software Trajecto, the previous acquisition function was in the C-programmed part be-cause the previous camera was working with an ISA port on the computer which could be easilydescribe in C.

    The new camera is working by the IP network so the communication could be directly describein the Java-programmed part. But we quickly saw that the program was using global variables. Sowe had to stop and must decide if we will modify all the C code to avoid global variables or findinga C-programmed acquisition library.

    We took the second solution first and we find one library that may surely concur: libcurl(http://curl.haxx.se/).

    Then we had to write a first acquisition function to acquire images. We did and tested it quickly.

    s t a t i c s i ze_t write_data ( void ptr , s i z e_t s i z e , s i z e_t nmemb, void stream ){

    return fw r i t e ( ptr , s i z e ,nmemb, ( FILE ) stream ) ;}

    i n t main ( void ){

    / I n s t a n t i a t i o n /CURL cu r l ;CURLcode r e s ;

    / I n i t i a l i s a t i o n /i f ( ( c u r l = cur l_easy_in i t ( ) ) == NULL){

    f p r i n t f ( s tde r r , " I n i t i a l i s a t i o n f a i l e d :cu r l_g loba l_ in i t ( )\ n " ) ;

    e x i t ( 0 ) ;}

    / Debug func t i on /curl_easy_setopt ( cur l ,CURLOPT_VERBOSE, 1 ) ;

    / URL De f i n i t i o n /curl_easy_setopt ( cur l ,CURLOPT_URL,

    "http : / / 192 . 1 6 8 . 0 . 9 0 / jpg / image . jpg " ) ;

    11

  • / No prog r e s s meter /curl_easy_setopt ( cur l , CURLOPT_NOPROGRESS, 1L ) ;

    / Write func t i on d e f i n i t i o n /curl_easy_setopt ( cur l ,CURLOPT_WRITEFUNCTION, write_data ) ;

    / Write func t i on params /curl_easy_setopt ( cur l ,CURLOPT_WRITEDATA, f i c h i e r ) ;

    / Retr i eve in fo rmat ion /r e s = curl_easy_perform ( cu r l ) ;

    / Cleanup /curl_easy_cleanup ( cu r l ) ;

    }

    We run into another issue which was that the obtain image was always formed of 128 bytes.We found in the camera datasheet that to acquire the image we need an HTTP Authentication toreach data. Fortunately, the library bears it and we had only two lines to add:

    / HTTP Authent icat ion /curl_easy_setopt ( cur l ,CURLOPT_HTTPAUTH,CURLAUTH_BASIC) ;cur l_easy_setopt ( cur l ,CURLOPT_USERPWD," root : t r a j e c t o " ) ;

    3.2 Adaptation in TrajectoHence, we had our function we should now locate how we will insert it in Trajecto. So we askedMr Eric WAJNBERG to show us how to acquire an image in Trajecto.

    Knowing how it works, we put in every function printf -or print- method then we can follow thesequence of functions and methods. We find these links to acquire an image:

    12

  • Figure 2: Functions sequence acquiring an image

    In these function (cf. appendix B & C) we saw that the program were for 512x512 pixels images.With the new camera we only cant have square image, we only have 4:3 format. We note thatwe will solve that issue later by cutting a part of the image or suit the code to use with the newcamera.

    Reading the code we saw that the program was treating bitmap images. Yet, we were only able toacquire jpeg compressed images from the camera. So we thinked about implement a decompressionfunction or find a way to reach pixel matrix in jpeg.

    We couldnt find a way to reach the matrix without using a decompression function.So we had a talk with Mr Eric WAJNBERG that told us he wants to have a rate of at least 20

    images/seconds. So get through a decompression function would be too slow. We measured it andwe could only get 1 or 2 images/seconds.

    We then shared our issue with Mr Serge MILLON. He told us about a little society Agix whichis working on Axis solution -brand of the camera- that may help us finding a way to advance in ourproject.

    We phoned them and they find us a better solution: we can directly acquire a bitmap image.Happy to learn it we directly programmed and tested it. It worked well but we reached anotherissue. Our acquisition function were writing data into a file and we after read it to do the treatment.The timing report was still not good, it takes to long to access the hard drive ...

    We should find a way to store data in the memory. We dont find the solution in our librarydocumentation. We tried to ask the library support but it was only a professional support. Non-

    13

  • free. We decided to see Mr Vincent GRANET, he maybe will give us a clue finding a solution. Andthat is what happened, he saw that libcurl was an opensource library, so we have to directly modifythe library source to get our data in the memory and not in the hard drive.

    We took times at this point because many concepts was there: modifying an existing library,moreover modifying a callback function that can have everyname we want. So it was really hard tofind where we had to modify but with some clues and help we succeeded.

    Now, we finally get an encouraging timing report. Lets get into the implementation of this codeinto Trajecto.

    3.3 JNIWith Trajecto we also learned that a software can work with multiple programming language. Infact, Trajecto is design with Java and C.

    The two programming language are linked by a programming framework JNI (Java NativeInterface) that allows Java code running in a JVM (Java Virtual Machine) to call and to be calledby native applications (programs specific to a hardware and operating system platform) and librarieswritten in other languages, such as C.

    These two programming language mingled we have to be really careful when we exchange databetween the two.

    The issue we had is that Java is manipulating the bitmap data as "byte" type. This typeis present in C with the "unsigned char" type. But there is limitations in C using the keywordunsigned and we could not use it because of libcurl that didnt accept that type. So we used the"char" type. The difference between the two is that byte is unsigned (data can get value from 0 to255) and char is signed (-128 to 127). So we add 128 to all the value recovered.

    14

  • 4 JPEG/BMPThe camera generates a JPEG image while Trajecto is designed for a bitmap,

    Therefore, it didnt work with the camera image. In order to adjust the camera image inTrajecto, it was necessary to understand how bitmap and JPEG images are formed.

    4.1 Bitmap ImageA BMP file is a bitmap, ie a graphic image storing the pixels in a table of points and managingcolor either in true color or wtih indexed palette.

    The structure of a bitmap is :

    a file header

    bitmap informations headers

    a color palette

    bitmap data

    4.1.1 File header

    The file header is at the start of the file and is used to identify the file. All of the integer values arestored in little-endian format : least-significant byte first.

    The file header has four fields:

    the magic number used to identify the BMP file: 2 bytes.

    the size of the BMP file in bytes:4 bytes

    4 bytes reserved

    the offset,starting address, of the byte where the bitmap data can be found: 4bytes.

    4.1.2 Bitmap informations headers

    The bitmap informations headers provides information about the image, including its dimensionsand colors. These headers is

    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1940 0 0 0 width height 1 0 8 0 0 0 0 020 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

    image size x x x x x x x x number of colors x x x x

    Table 1: Bitmap headers informations

    15

  • 4.1.3 Color palette

    Color palette is optional. When a palette is set, it contains 4 bytes successively for each of itsrepresentatives:

    The blue component (1 byte)

    The green component (1 byte)

    The red (1 byte)

    A byte reserved

    4.1.4 Bitmap data

    Pixels are stored "upside-down" , starting in the lower left corner, going from left to right, and thenrow by row from the bottom to the top of the image.

    The images in 2 colors use 1 bit per pixel, which means that a byte used to encode 8 pixels

    The images in 16 colors use 4 bits per pixel, which means that a byte used to encode 2 pixels

    The images in 256 colors use 8 bits per pixel, which means that one byte code each pixel.

    The color images use 24 bits per pixel, which means 3 bytes to encode each pixel.

    Each line of the image must include a total number of bytes that is a multiple of 4, if it is not thecase, the line must be supplemented with 0.

    4.2 JPEG ImageJPEG is a commonly used method of compression for photographic images. The degree of com-pression can be adjusted, allowing a selectable tradeoff between storage size and image quality.

    JPEG is a lossy compression method, which removes information from the image.A JPEG image consists of a sequence of segments, each beginning with a marker, each of which

    begins with a 0xFF byte followed by a byte indicating what kind of marker it is. Some markersconsist of just those two bytes; others are followed by two bytes indicating the length of marker-specific payload data that follows.

    The encoding of JPEG file consists of several steps:

    1. The representation of the colors in the image is converted from RGB to YCbCr, consistingof one luma component (Y), representing brightness, and two chroma components, (Cb andCr), representing color. This step is sometimes skipped.

    2. The resolution of the chroma data is reduced, usually by a factor of 2. This reflects the factthat the eye is less sensitive to fine color details than to fine brightness details.

    3. The image is split into blocks of 88 pixels, and for each block, each of the Y, Cb, and Crdata undergoes a discrete cosine transform (DCT). A DCT is similar to a Fourier transformin the sense that it produces a kind of spatial frequency spectrum.

    16

  • 4. The amplitudes of the frequency components are quantized. Human vision is much moresensitive to small variations in color or brightness over large areas than to the strength of high-frequency brightness variations. Therefore, the magnitudes of the high-frequency componentsare stored with a lower accuracy than the low-frequency components. The quality setting ofthe encoder (for example 50 or 95 on a scale of 0100 ) affects to what extent the resolutionof each frequency component is reduced. If an excessively low quality setting is used, thehigh-frequency components are discarded altogether.

    5. The resulting data for all 88 blocks is further compressed with a loss-less algorithm, a variantof Huffman encoding.

    4.3 Considered solutionIn order to resolve this problem: the type of image , we thought of several solutions:

    Work directly on JPEG images pixels

    Convert JPEG in bitmap with a C program

    Find a solution with AXIS the suppliers of camera

    4.3.1 Work directly on the JPEG images pixels

    With this solution we have to directly manipulate the JPEG images matrix, so we ought to changemost of the functions which already exist on Trajecto. But this changes would have taken too muchtime, moreover the Trajecto was created some years ago, so it would have been difficult to asksome clarification on functions. And Trajecto program works very well with a bitmap image, thusit would have been dangerous to change it.

    Therefore, this solution was abandoned.

    4.3.2 Convert JPEG into bitmap

    Then we wanted to convert the JPEG image into a bitmap with a C program. So, we found alibrary : jpeglib which allows to manipulate JPEG images.

    We created a program which, using this library, can change the format of the image. We couldsee that for a JPEG image taken on Internet, a BMP image was created in a file (cf. appendix D)

    But the issue, with this solution, is that we copy the image on the disk so we lost some time toget a bitmap image. And objective is to get 20 images/sec, so we calculate the execution time ofour program, then we had for 20 images a time of 750 ms. This is very fair because the time wascalculated without manipulation in Trajecto.

    4.3.3 Find a solution with AXIS the suppliers of camera

    Then we called AXIS: manufacturer of the camera, to know if it exists a C library with the camerain order to change the format of the image. They give us a piece of program and an URL whichwas really more interesting for us, because it directly gives us.

    17

  • We managed to have a bmp image generated by the camera and we could display itin a file with our C program. It was able to include this program in Trajecto, wemanaged to have an image in Trajecto but it is not the same as the image from thecamera.

    18

  • 5 Image processingThe matrix containing the pixels of an BMP image is the matrix chunk.memory of char* type.It is observed that this image recovered in a file using a writing function is correct. Whereas theobtained image under trajecto is completely different. It is observed that the obtained image is arepetition of a part of the original image acquired by the camera with a 90-rotation.

    We have to find where and why this issue came. It could be a function which was called by anindirect way and which could modified the image. Or maybe the image format? Issues could benumerous and then we should find the good one. Thus we have to begin the study obtained image.

    5.1 Issue sourceBy passing its size in the code with chunk.size. The original image had a dimension of 320*240pixels, the dimension of the recovered table should be 320*240 too, multiplied by the number ofbytes per pixels plus some bytes for the signature, the headers and the palette. Nevertheless, therecovered table was 345654 bytes long, more than 320*240=76800. This could correspond to anbitmap of 4 bpp (bytes per pixel). So we chose to show this issue to Mr Million to have an externalvue on the subject. After this meeting, Mr Million guided us to a possible issue on the BMP typeor JNI conversion between string and table of bytes.

    On PhotoShop we saw that we can generate various type of BMP with a different numberof bpp. So we generated these various types and we put them on Internet to then simulate undertrajecto the acquisition of these image by IP. We observed that the image was correctly recoveredunder Trajecto for an BMP image with a 512*512 dimension and with 1 bpp. A new issue come:the size of the image as well as its definition.

    5.2 Size and definition of the BMP pictureAfter some alterations in the code regarding the dimension of the string in several file as well in theJava part as in the C part. Trajecto with an image sized as 320*240 with 1 bpp is working now.

    So we have to find what is the definition of the BMP returned by the camera. During this year,one of our tutorials in Java was related to the study of an BMP image. With this tutorials wecould read, in the heading, the dimension of the pixels matrix which was 230400 bytes long. Sothe image had 3 bpp.

    But we had an other issue: why the size of the table obtained was 345654 bytes long? Therewas 115254 additional bytes into the pixels matrix. This number was too big to only describe theheading, the signature and the palette. There was a new issue with the matrix size.

    5.3 Problem with the matrix sizeWhile we simulated with our images on Internet, we observed the dimension returned by theprogram for the matrix was 76900 bytes which equals the correct number of pixel of the image plussome bytes for the information of file BMP. Whereas for an obtained image by the camera if it isconsidered that the information of the BMP holds on some bytes, the additional number of bytesis really important. So we couldnt modify the pixels matrix if we couldnt recover it.

    We wondered how come these additional bytes. It surely comes from the callback function asso-ciated with the library libcurl which is called many times because of the authentification necessaryto be connected to the camera. Because it is only the difference between an image obtained bythe camera and another obtained by Internet. But the issue was not to know the origin of these

    19

  • additional bytes but to find a means of recovering the matrix of the pixels and the informations ofthe image.

    Several solutions were considered. Firstly, we wrote a code in MATLAB (cf. appendix E) togenerate a textual file containing the binary code corresponding to the picture. Then we have tosearch in this binary code the magic number in the heading of a BMP which is, in hexadecimal,0x424D. But the issue was that considering the numbers of bytes in this file, this number didntappear one time moreover this magic number corresponds to the OS from where the image wasgenerated. 0x424D correspond to a Windows OS.

    The second solution was to write in the file image only a part of the matrix and observe the.bmp file. We wanted to recover the pixels matrix as well as headers informations. But we thoughtthese data were at the end of the matrix. We have to pass only the end of the table but we doesntobtained a BMP picture. So we decided to keep only the beginning and we obtained a part of theimage. The we knew that the additional bytes were after the file. We obtained the complete image:230454 bytes long. This is a table of pixel of 230400 bytes (230*420*3) plus 54 bytes for headersinformations. Now that we had our pixels matrix, it was necessary to find a conversion method.

    5.4 Conversion from 3 bpp to 1 bppOur tutorial in Java was also very useful for this part. The 3 bytes describing each pixels correspondseach one to a color which are red, green and blue.

    In the string values are between -128 and 127, so we used a function unSigned to have onlypositive values thus ranging between 0 and 256 which correspond to the byte type in Java.

    / Function unSigned Param : d : the char Return : the a s s o c i a t ed p o s i t i v e i n t e g e r va lue to the char/i n t unSigned ( char d){

    return d+128;}

    The second function makes it possible starting from a number of bytes to obtain a correspondinginteger.

    / Function ge t In t Param : d : s t r i n g Param : o f s : index from which we s t a r t r e cove r i ng the value Param : l g t : number o f bytes we w i l l use Return : the a s s o c i a t ed i n t e g e r to the l g t bytes/i n t g e t In t ( char d , i n t o f s , i n t l g t ){

    i n t i , j , s=0;f o r ( i=t a i l l e 1; i >=0; i){

    i n t tmp = unSigned (d [ o f s+lgt1 i ] ) ;

    20

  • f o r ( j=t a i l l e 1; j>i ; j)tmp = 256

    s += tmp ;}return s ;

    }

    Then the function conversion create a table containing only heading, signature, palettes andthe new pixels matrix. In this new table the information part is non-changed then in the pixelsmatrix we read 3 bytes per 3 bytes to generate an associated integer. This integer is then comparedwith a threshold value to know if we have to generate a white pixel on a byte (+255) or a blackpixel (0). This threshold value is obtained by taking the central value of the possible integer withgenerated from 3 bytes.

    We observed that the obtained image obtained is shifted on the right because between thepalette and the beginning of the pixels matrice, there is a gap of 18 octets.

    / Function conver s i on Param : mem: the p ixe l s matrix Return the convert p ixe l s matrix/

    char conver s i on ( char mem){

    i n t x , y ;char tab = mal loc ( s i z e o f ( char )320240) ;

    / Browse the p ixe l s matrix 3 per 3 bytes /i n t las t_pxl = 3202401;

    f o r ( y=0;y

  • We finally obtain an image with the camera in Trajecto (cf. appendix E).

    22

  • ConclusionThe project tooked place in the informatics domain and especially into informatics languages Cand Java. That helped us to strengthen our bases in programming.

    The constraints were numerous during this project. First of all, Trajecto is a software startedseveral years ago and so, many students change its code. It were almost no comments in this code.So the comprehension of this code was very long and very hard at the beginning of our project.

    The work that we have done was primarily a work of debug with the many ways which exists indata processing (screen impression, simplification of the code by removing the useless functions,. . . ).We improved our reflexion capacities face an issue in data processing and of course it is not themost pleasant part in data processing.

    We have also improved other fields: image processing and in particular the BMP type. Weexpanded our knowledge also on JPEG images. We could exploit of another tools to help us in thisfield such as Matlab. We could see that the problems encountered during the image processing arenot easy to interpret then to solve them.

    The first objective takes more time than we had plan. So, we realized its very difficult to respecta planning because we didnt know problems we could have.

    Thank to this project, we really could touch several fields for then being confronted with prob-lems of various nature to finally solve them with our team. The study of an issue as a team wasvery rewarding because each members of the team have a different vue on it. Whence the solutionswere numerous and allowed us to work on various solutions to finally choose the best.

    23

  • Appendix

    A Gantt Diagram

    24

  • B Acquiring an image (C-source)

    25

  • 26

  • C Acquiring an image (Java-source)

    27

  • 28

  • D Jpeg2bmp.c

    29

  • 30

  • 31

  • 32

  • E Matlab: obtain the binary code of an image

    33

  • F Get an image in Trajecto

    34