Question

In: Computer Science

Please Complete this C Code using the gcc compiler. Please include comments to explain each added...

Please Complete this C Code using the gcc compiler. Please include comments to explain each added line.

/*This program computes the Intersection over Union of two rectangles
as a percent:

IoU = [Area(Intersection of R1 and R2) * 100 ] / [Area(R1) + Area(R2) - Area(Intersection of R1 and R2)]

The answer will be specified as a percent: a number between 0 and 100.
For example, if the rectangles do not overlap, IoU = 0%. If they are
at the same location and are the same height and width, IoU = 100%.
If they are the same area 30 and their area of overlap is 10, IoU =
20%.

Input: two bounding boxes, each specified as {Tx, Ty, Bx, By), where
   (Tx, Ty) is the upper left corner point and
   (Bx, By) is the lower right corner point.
These are given in two global arrays R1 and R2.
Output: IoU (an integer, 0 <= IoU < 100).

In images, the origin (0,0) is located at the left uppermost pixel,
x increases to the right and y increases downward.
So in our bounding box representation, it will always be true that:
Tx < Bx and Ty < By.

Assume images are 640x480 and bounding boxes fit within these bounds and
are always of size at least 1x1.

IoU should be specified as an integer (only the whole part of the division),
i.e., round down to the nearest whole number between 0 and 100 inclusive.

FOR FULL CREDIT (on all assignments in this class), BE SURE TO TRY
MULTIPLE TEST CASES and DOCUMENT YOUR CODE.
*/

#include
#include

//DO NOT change the following declaration (you may change the initial value).
// Bounding box: {Tx, Ty, Bx, By}
int R1[] = {64, 51, 205, 410};
int R2[] = {64, 51, 205, 410};
int IoU;

/*
For the grading scripts to run correctly, the above declarations
must be the first lines of code in this file (for this homework
assignment only). Under penalty of grade point loss, do not change
these lines, except to replace the initial values while you are testing
your code.

Also, do not include any additional libraries.
*/

int main() {

// insert your code here

IoU = -999; // Remove this line. (It's only provided so that shell code compiles w/out warnings.)

printf("Intersection over Union: %d%%\n", IoU);
return 0;
}

Solutions

Expert Solution

// C program that computes the Intersection over Union of two rectangles as a percent

#include <stdio.h>

#include <stdlib.h>

//DO NOT change the following declaration (you may change the initial value).

// Bounding box: {Tx, Ty, Bx, By}

int R1[] = {64, 51, 205, 410};

int R2[] = {64, 51, 205, 410};

int IoU;

/*

For the grading scripts to run correctly, the above declarations

must be the first lines of code in this file (for this homework

assignment only). Under penalty of grade point loss, do not change

these lines, except to replace the initial values while you are testing

your code.

Also, do not include any additional libraries.

*/

int main(void) {

       int Inter[4]; // coordinates for the intersection rectangle

       // determine the top coordinate

       // x value – will be the maximum of the Tx

       if(R1[0] > R2[0])

             Inter[0] = R1[0];

       else

             Inter[0] = R2[0];

       // y value – will be maximum of the Ty

       if(R1[1] > R2[1])

             Inter[1] = R1[1];

       else

             Inter[1] = R2[1];

       // determine the bottom coordinate

       // x value – minimum of the Bx

       if(R1[2] < R2[2])

             Inter[2] = R1[2];

       else

             Inter[2] = R2[2];

       // y value – minimum of the By

       if(R1[3] < R2[3])

             Inter[3] = R1[3];

       else

             Inter[3] = R2[3];

       // calculate area of R1

       int Area_R1 = (R1[2]-R1[0])*(R1[3]-R1[1]);

       // calculate area of R2

       int Area_R2 = (R2[2]-R2[0])*(R2[3]-R2[1]);

       // calculate area of Intersection rectangle

       int Area_Inter = 0;

       // if the rectangles do intersect

       if(Inter[2] > Inter[0])

             Area_Inter = (Inter[2]-Inter[0])*(Inter[3]-Inter[1]);

       // calculate IOU

       IoU = (Area_Inter*100)/(Area_R1 + Area_R2 - Area_Inter);

       printf("Intersection over Union: %d%%\n", IoU);

       return EXIT_SUCCESS;

}

//end of program

/*

* Test Cases:

*

* Test Case 1 :

* int R1[] = {0, 0, 10, 10};

* int R2[] = {5, 0, 10, 10};

* IoU = 50%

*

* Test Case 2:

* int R1[] = {0, 0, 10, 10};

* int R2[] = {5, 5, 20, 20};

* IoU = 8%;

*

* Test Case 3:

* int R1[] = {0, 0, 10, 10};

* int R2[] = {15, 15, 20, 20};

* IoU = 0%

*

* Test Case 4:

* int R1[] = {64, 51, 205, 410};

* int R2[] = {64, 51, 205, 410};

* IoU = 100%

*

* Test Case 5:

* int R1[] = {0, 0, 10, 10};

* int R2[] = {5, 5, 7, 8};

* IoU = 6%

*/

Output:


Related Solutions

Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include #define END_OF_LIST -999 using namespace std; /* * */ int exercise_1() { int x = 100; int *ptr; // Assign the pointer variable, ptr, to the address of x. Then print out // the 'value' of x and the 'address' of x. (See Program 10-2) return 0; } int exercise_2() { int x = 100; int *ptr; // Assign ptr to the address of...
#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell {...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell { int val; Cell *next; }; int main() { int MAX = 10; Cell *c = NULL; Cell *HEAD = NULL; srand (time(NULL)); for (int i=0; i<MAX; i++) { // Use dynamic memory allocation to create a new Cell then initialize the // cell value (val) to rand(). Set the next pointer to the HEAD and // then update HEAD. } print_cells(HEAD); }
Please complete following c++ code asap using following prototypes complete each missing part / Linked list...
Please complete following c++ code asap using following prototypes complete each missing part / Linked list operations int getLength() const {return length;} void insertNode(College); bool deleteNode(string); void displayList() const; bool searchList(string, College &) const; }; main.cpp /*   Build and procees a sorted linked list of College objects. The list is sorted in ascending order by the college code. Assume that the college code is unique. */ #include <iostream> #include <fstream> #include <string> #include "LinkedList.h" using namespace std; void buildList(const string...
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
Use the Compiler Explorer with the MIPS compiler to compile the following C code. Assuming this...
Use the Compiler Explorer with the MIPS compiler to compile the following C code. Assuming this function is called with the parameter n = 5… int summarize(int n) { int sum = 0; for (int i = 0; i < n; i++) { sum += i; } return sum; } c) Compile the code using the ARM gcc 8.2 compiler. Add the –O1 compiler option, which asks the compiler to optimize for speed (at least to one level). What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT