ECE 484W: Assignment #4: Author
ECE 484W: Assignment #4: Author
Author:
Warren Shields
UIN: 01080181
Group Members:
Jermahre Moore
Honor Code:
ODU Honor Code must be adhered to. This means that homework assignments and design
projects are to be the work of an individual student group only. Evidence such as identical results
and/or wording of sections of a report, if strong enough, will be reported to the University
Hearing Officer in charge of administrating the ODU Honor Code. If the violation is deemed
sufficient, a permanent record of this infraction will be placed on the student's official university
transcript for the first offense! Subsequent offenses could result in dismissal from the university.
Abstract
Table of Contents
List of Figures...............................................................................................................................................4
List of Tables................................................................................................................................................5
1. Introduction.........................................................................................................................................6
1.1. Objective......................................................................................................................................6
1.2. Image Overlay..............................................................................................................................6
1.3. Brightness and Contrast Control..................................................................................................6
1.4. Report Structure..........................................................................................................................6
2. Design Methodology............................................................................................................................7
2.1. Image Overlay..............................................................................................................................7
2.1.1. Sender..................................................................................................................................8
2.1.2. Receiver.............................................................................................................................11
2.2. Brightness and Contrast Control................................................................................................13
2.2.1. Sender................................................................................................................................13
2.2.2. Receiver.............................................................................................................................14
3. Analysis and Results...........................................................................................................................15
4. Alternative Design.............................................................................................................................15
5. Additional Considerations in Design Process.....................................................................................15
6. Broader Impacts................................................................................................................................15
7. Individual Contribution......................................................................................................................15
References.................................................................................................................................................16
Appendix...................................................................................................................................................16
List of Figures
Figure 1: Image overlay process..................................................................................................................7
Figure 2: Image overlay communication flow..............................................................................................7
Figure 3: New transfer buttons added to GUI..............................................................................................8
Figure 4: UDPclass constructor binds to address and port..........................................................................9
Figure 5: Algorithm for portioning number of bytes written.....................................................................10
Figure 6: Writing start and operation identifier to socket.........................................................................11
Figure 7: Writing end identifier to socket..................................................................................................11
Figure 8: Image overlay receiver GUI.........................................................................................................12
Figure 9: Append all bytes from operation to private member variable...................................................12
Figure 10: Image overlay algorithm...........................................................................................................12
Figure 11: Brigtness/contrast control sender GUI.....................................................................................13
Figure 12: sendSlider function definition...................................................................................................14
Figure 13: Brightness/contrast control receiver........................................................................................15
List of Tables
Table 1: Image overlay receiver operations...............................................................................................12
Table 2: Brightness/contrast control receiver operations.........................................................................15
1. Introduction
1.1. Objective
The objective of this lab was to modify the previously designed Qt GUIs where one could
overlay an image over a base image, and one could alter the brightness and contrast of a loaded
image via sliders. Modifications will allow image transfer to the VEEK-MT2S FPGA board from
the Qt GUIs via Ethernet interface. Qt’s UDP socket library, QUdpSocket, is utilized for data
transfer between the two devices. The GUI is then to communicate values over to the board to
perform the appropriate image processing techniques.
We defined a UDP class is defined to establish member function for the transferal of the image.
The member functions utilize the Qt Creator library, QUdpSocket, which successfully
establishes UDP socket communication between the GUI and VEEK FPGA board. The image
must be configured into datagrams so that the image can be sent to the binded UDP socket. To
accomplish this process, we defined a function called sendImage which converts the loaded
image into datagrams so that we can transmit the image to the UDP socket. The function initially
writes a 9-byte array to the socket where in the first five bytes read “Start”. This process notifies
the receiver that data from the GUI is being sent to the receiver and needs to be further decoded.
The last 4 bytes of the 9-byte array read “Load” that is stored in a string id variable format. This
communicates to the receiver that the image data is being delivered and must be decoded
accordingly. The process is displayed in Fig. 2
Figure 1: Starts communication for sending the image through the socket.
The image is downscaled to 256 by 256 before the actual image is converted to a byte
array. This method was performed to prevent data loss that would’ve interfered with sending
large packets of information via UDP. We must keep in mind that the QUdpSocket library only
enables users to write to the socket at 1,024 bytes at a time. Due to this constraint, the datagrams
must be sent in multiple portions of 1,024 bytes or less. An algorithm was constructed that writes
the datagrams to the socket in portions of 1,024 bytes or less until all data are sent. The
implementation of this design in Qt is displayed in Fig. 3.
¿ of Bytes
¿ Loops= +1 (1)
1024
The sendImage function is then called in the slot function, on_transfer_btn_clicked, for
the button on the GUI labeled “Transfer Image”. This will result in the sending of the image data
to the receiver side when the “Transfer Image” button on the GUI is pressed.
Finally, “End” is delivered to the socket for it to communicate to the receiver that all data
has been sent. Once, the receiver receives “End”, then the decoding process is concluded, and the
final image can be displayed.
The sendSlider function is defined in the UPD class function which is ultimately responsible for
delivering the numerical value that is associated with the moved slider to the receiver end. Once
the values are delivered to the receiver end, it is then to be decoded. Similar to the sendImage
function, the sendSlider function initializes its communication process by sending a 9-byte
array. In the byte array, the first five bytes are “Start” and the last four read a 4 byte identifier.
For this particular function, when the brightness slider is moved, the id is “Brig”. When the
contrast slider is moved, the id is “Cont”. The number that is affixed with the slider position is
then converted to a 2-byte array and appended to the end of the nine preceding bytes of the array.
Likewise, to the sendImage function, “End” is written to the very end of the socket to
communicate to the receiver that all data has been sent. Once all data is completed, the contrast
and brightness can be applied.
The sendImage function is then called in both slot functions for the contrast and
brightness sliders. Once the function is called, “Brig” is passed as the identifier into brightness
slot function and “Cont” is passed into the identifier in the contrast slot function.
2.2 Receiver
The program for the Receiver end is written in C++. It is a modification of the existing
VEEK-MT2s “camera_in” project which captures each frame from the FPGA’s on-board
camera display. Once each frame is capture, it displays it to the board’s LCD monitor. The
program must read pending datagrams from the socket. For this to established, we used the
“sys/socket.h” library and C++ coding to implement the UDP networking capabilities in the
program. Fig. 4 displays the complete flow diagram of the original design.
Figure 3: Flow Diagram for the Original Reciver.
Recall from Section 2.1. that the sendImage and sendSlider functions in the Sender program
both established communication by sending “Start” to the socket. A private member bool in the
D8MCapture class is set to true when the “Start” is received. Also, the D8MCapture class
contains a private member string combineBuffer. The character array buffer, holding the
received characters from the datagram, is appended to combineBuffer. This process will
continue in sequence until the sockets read “End”. Once the sockets read “End”, it will clear the
combineBuffer and set start to false. Setting start to false will stop the program from entering
the if statement.
Inside this for loop, the program also checks for the id sent from the sendImage and
sendSlider functions. The provided identifiers determine the opcode for the receiver which
determines the appropriate operation for the program. Table 1 details the program’s behaviors for
different opcodes. Note that the opcode is initialized as 0.
To avoid a contrast equivalent to 0, which would completely blacken the display, the
contrast value is initialized as 10 and will remain 10 until the transmitted value is greater than 10.
Note that 10 is selected as the minimum value because when the contrast is applied, the value is
multiplied 0.1. The reasoning for this will be explained later.
After the if statement, the program checks to see if an overlay image exists by checking
connected. If true, the program overlays the overlay image in the top corner of the camera frame
using OpenCV’s copyTo function. The program then applies the brightness and contrast values
with OpenCV’s convertTo function. As stated earlier, the contrast is multiplied by 0.1. This is
because convertTo intensifies the contrast exponentially. By dividing the slider values by 10, the
contrast intensifies more gradually as the sliders are moved. The brightness value is doubled to
get more immediate results when the brightness slider is moved.
The program then displays the new image by using OpenCV’s imshow function. The
program then continues to loop. As expected, the FPGA only displays what is on the camera as
there has yet to be an overlay or alteration of the brightness or contrast.
Figures 8-10 depict the results when the brightness and contrast sliders are changed.
Although the program successfully worked and satisfied each of its requirements, its
performance is not as sufficient. The average image load time of 1.76 is not instantaneous and
the brightness and contrast control time end up causing poor latency issues which results into
delayed contrast/brightness modulations when the slider values are changed quickly. Due to the
undesirable performance, quickly dragging the sliders can potentially result in discrepancies
between the slider values on the GUI and the brightness and contrast display on the FPGA. We
measured the average CPU usage of the design which resulted in 96% usage. This leads to the
program crashing when the contrast is changed by a lot in an instant amount of time. Our
Alternative Design which is included in the next section, discusses these problems and solutions
we use to remedy the effect.
3. Alternative Design
Recollecting back to the original design, the process captures frames from the camera, receives
data from the UDP socket, and decodes the datagrams in series. This process takes longer to
complete due to it being in series and must wait for one process to finish. It can be observed that
the camera capture and the UDP datagram receive and decode process, can be ran as independent
processes. Also, it is imperative to know that the non-blocking UDP sockets can lead to higher
CPU consumption due to the constant reading for data, even when there are no pending
datagrams to be read.
In our alternative design, the program is split into two different threads by using the C++
“thread” library, so that they can work in parallel. One process has the responsibility of capturing
the frames from the camera, performing the overall, and applying the brightness and contrast
values coherently. On the opposing end, the new thread is responsible for receiving the
datagrams from the socket and then decoding and processing the data.
Figure 8: Alternative design flow diagram.
Implementation of the new thread shifts the relevant blocks of a code to the function
receiver, which ultimately is made a class function for the D8MCapture. In the receiver
function, the socket is set to blocking because the it no longer blocks the camera capturing.
Implementation of this methodical approach makes the non-blocking setting unnecessary. The
new thread is then called in the main() as ‘thread
fprocessData(&D8MCapture::receiver,cap);’. This allows the function to be ran as a
separate thread that runs simultaneously with the main thread. Below, Table compares the results
between the original and alternative designs.
Metrics Original Alternative
Avg. Image Load Time ~1.76 sec ~25 ms
Avg. Brightness/Contrast Update Time ~51.2 ms ~0.16 ms
Avg. CPU Usage ~96% ~83%
Table 2: Original vs. alternative design.
As displayed, the collected shows that the alternative design gives approximately 70x
faster image load time, approximately 313x faster brightness and contrast update time, and
reduces CPU usage by 13%. To achieve the most optimal performance, it can be observed that
the use of multithreading and blocking sockets instead of non-blocking sockets will enhance
overall performance.