A general code, where the size of every variable can differ each time that the program runs:
// Created by Enrique Daniel Saldivar Carranza A01225963 and Fernanda Cano A00226352 on 16/11/15.
// Copyright © 2015 Enrique Daniel Saldivar Carranza and Fernanda Cano. All rights reserved.
// General code where the size of every variable can differ each time that the program runs
#include <iostream>
#include <cmath>
#define pi 3.14159265359
using namespace std;
char x;
double Ax,Ay,Bx,By,Cx,Cy, lmc, lmp, lop, w, h;
void calc_length (double a, double b, double c){
double scale, loc;
scale= a/b; //We get how many centimeters a pixels is
loc= c*scale;
cout<<"The length of your object is of: "<<loc<<" cm. "<<loc*0.39370079<<" inches.";
}
void calc_angle (double ax, double ay, double bx, double by, double cx, double cy){
double magnitud_AB, magnitud_AC, prod_punt, angle;
magnitud_AB= sqrt(pow((Bx-Ax),2) + pow((By-Ay),2));
magnitud_AC= sqrt(pow((Cx-Ax),2)+ pow((Cy-Ay),2));
prod_punt=((Bx-Ax)*(Cx-Ax))+((By-Ay)*(Cy-Ay));
angle= acos(prod_punt/(magnitud_AB * magnitud_AC));
cout<<"The interior angle in radians is: "<<angle<<", in degrees: "<<(angle*180)/pi<<endl;
cout<<"The exterior angle in radians is: "<<(2*pi)- angle<<", in degrees: "<<360-((angle*180)/pi)<<endl;
// You could get an error if when calculating the angle using the product point you get 0 in the denominator or if your numerator is bigger than your denominator (calculating the arccos of a number greater than 1)
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees. All of these using a digital picture (with a marker information if you want lengths)."<<endl<<endl;
cout<<"Do you want to get angles? (type 'a'), do you want to get a length? (type 'l') ";
cin>>x;
while((x!='a')&&(x!='A')&&(x!='l')&&(x!='L')){
cout<<"You did not type a valid character. Do you want to get angles? (type 'a'), do you want to get a length? (type 'l')? ";
cin>>x;
}
if ((x=='a')||(x=='A')){
cout<<"Give me the coordinates of point A (where the two lines intersect)"<<endl;
cout << "x:";
cin >> Ax;
cout << "y:";
cin >> Ay;
cout<<"Give me the coordinates of point B: "<<endl;
cout << "x:";
cin >> Bx;
cout << "y:";
cin >> By;
cout<<"Give me the coordinates of point C:"<< endl;
cout<<"x:";
cin>>Cx;
cout << "y:";
cin >>Cy;
calc_angle (Ax,Ay,Bx,By,Cx,Cy);
}
else if ((x=='l')||(x=='L')){
cout<<"What is the resolution of the image:\n";
cout<<"W: ";
cin>>w;
cout<<"H: ";
cin>>h;
cout<<"Tell me the length of your marker (in cm.): ";
cin>>lmc;
cout<<"Tell me the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me the length of your object (in pixels): ";
cin>>lop;
while(((lmp>=w)&&(lmp>=h))||((lop>=w)&&(lop>=h))){
cout<<"You are giving a pixel size of one of your objects bigger than your actual image, the objects you want to measure MUST be inside the image.\n";
cout<<"Tell me again the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me again the length of your object (in pixels): ";
cin>>lop;
}
calc_length(lmc, lmp, lop);
}
return 0;
}
An ideal conditions code, where we put as constants the values for the variables that we discovered worked better in our environment:
//
// main.cpp
// Complete_specified
//
// Created by Enrique Daniel Saldivar Carranza A01225963 and Fernanda Cano A00226352 on 16/11/15.
// Copyright © 2015 Enrique Daniel Saldivar Carranza and Fernanda Cano. All rights reserved.
// ideal conditions code, where we put as constants the values for the variables that we discovered worked better in our environment
#include <iostream>
#include <cmath>
#define pi 3.14159265359
#define scale 0.0441176 // This is an average of the scale in the experiments we did were 1cm::0.0441176 pixels
using namespace std;
char x;
double Ax,Ay,Bx,By,Cx,Cy, lop;
void calc_length (double a){
double loc;
loc= a*scale;
cout<<"The length of your object is of: "<<loc<<" cm. "<<loc*0.39370079<<" inches."<<endl;
cout<<"There can be an %error around 4%";
}
void calc_angle (double ax, double ay, double bx, double by, double cx, double cy){
double magnitud_AB, magnitud_AC, prod_punt, angle;
magnitud_AB= sqrt(pow((Bx-Ax),2) + pow((By-Ay),2));
magnitud_AC= sqrt(pow((Cx-Ax),2)+ pow((Cy-Ay),2));
prod_punt=((Bx-Ax)*(Cx-Ax))+((By-Ay)*(Cy-Ay));
angle= acos(prod_punt/(magnitud_AB * magnitud_AC));
cout<<"The interior angle in radians is: "<<angle<<", in degrees: "<<(angle*180)/pi<<endl;
cout<<"The exterior angle in radians is: "<<(2*pi)- angle<<", in degrees: "<<360-((angle*180)/pi)<<endl;
// You could get an error if when calculating the angle using the product point you get 0 in the denominator or if your numerator is bigger than your denominator (calculating the arccos of a number greater than 1)
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees. All of these using information from a digital picture ."<<endl<<endl;
cout<<"Do you want to get angles? (type 'a'), do you want to get a length? (type 'l') ";
cin>>x;
while((x!='a')&&(x!='A')&&(x!='l')&&(x!='L')){
cout<<"You did not type a valid character. Do you want to get angles? (type 'a'), do you want to get a length? (type 'l')? ";
cin>>x;
}
if ((x=='a')||(x=='A')){
cout<<"Give me the coordinates of point A (where the two lines intersect)"<<endl;
cout << "x:";
cin >> Ax;
cout << "y:";
cin >> Ay;
cout<<"Give me the coordinates of point B: "<<endl;
cout << "x:";
cin >> Bx;
cout << "y:";
cin >> By;
cout<<"Give me the coordinates of point C:"<< endl;
cout<<"x:";
cin>>Cx;
cout << "y:";
cin >>Cy;
calc_angle (Ax,Ay,Bx,By,Cx,Cy);
}
else if ((x=='l')||(x=='L')){
cout<<"You have to take the picture with a camera of resolution 2448 x 3264 pixels, and you have to take the picture 1 meter away from the object (in order to get better results)."<<endl;
cout<<"Tell me the length of your object (in pixels): ";
cin>>lop;
calc_length (lop);
}
return 0;
}
A "without marker" code, where with the discoveries that we made with the experiments, we were able to take the marker out, and now you just need to give the distance from where the picture was taken as an input:
// Created by Enrique Daniel Saldivar Carranza A01225963 and Fernanda Cano A00226352 on 16/11/15.
// Copyright © 2015 Enrique Daniel Saldivar Carranza and Fernanda Cano. All rights reserved.
// without marker" code, where with the discoveries that we made with the experiments, we were able to take the marker out, and now you just need to give the distance from where the picture was taken as an input
#include <iostream>
#include <cmath>
#define pi 3.14159265359
#define constant 0.04194745389 //relation between scale and meter from a resolution of 2448 x 3264 pixels
using namespace std;
char x;
double Ax,Ay,Bx,By,Cx,Cy, d, op;
void calc_length (double a, double b){
double size;
size= constant*a*b;
cout<<"The length of your object is of: "<<size<<" cm. "<<size*0.39370079<<" inches."<<endl;
cout<<"There can be a %Error around 5%, the %Error decreases as you get closer to 2 m.";
}
void calc_angle (double ax, double ay, double bx, double by, double cx, double cy){
double magnitud_AB, magnitud_AC, prod_punt, angle;
magnitud_AB= sqrt(pow((Bx-Ax),2) + pow((By-Ay),2));
magnitud_AC= sqrt(pow((Cx-Ax),2)+ pow((Cy-Ay),2));
prod_punt=((Bx-Ax)*(Cx-Ax))+((By-Ay)*(Cy-Ay));
angle= acos(prod_punt/(magnitud_AB * magnitud_AC));
cout<<"The interior angle in radians is: "<<angle<<", in degrees: "<<(angle*180)/pi<<endl;
cout<<"The exterior angle in radians is: "<<(2*pi)- angle<<", in degrees: "<<360-((angle*180)/pi)<<endl;
// You could get an error if when calculating the angle using the product point you get 0 in the denominator or if your numerator is bigger than your denominator (calculating the arccos of a number greater than 1)
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees. All of these using information from a digital picture."<<endl<<endl;
cout<<"Do you want to get angles? (type 'a'), do you want to get a length? (type 'l') ";
cin>>x;
while((x!='a')&&(x!='A')&&(x!='l')&&(x!='L')){
cout<<"You did not type a valid character. Do you want to get angles? (type 'a'), do you want to get a length? (type 'l')? ";
cin>>x;
}
if ((x=='a')||(x=='A')){
cout<<"Give me the coordinates of point A (where the two lines intersect)"<<endl;
cout << "x:";
cin >> Ax;
cout << "y:";
cin >> Ay;
cout<<"Give me the coordinates of point B: "<<endl;
cout << "x:";
cin >> Bx;
cout << "y:";
cin >> By;
cout<<"Give me the coordinates of point C:"<< endl;
cout<<"x:";
cin>>Cx;
cout << "y:";
cin >>Cy;
calc_angle (Ax,Ay,Bx,By,Cx,Cy);
}
else if ((x=='l')||(x=='L')){
cout<<"You need you to take the picture using a camera with a resolution of 2448 x 3264 pixels, and I need to know the distance from where the picture was taken, as well as the size of the object in pixels."<<endl;
cout<<"Distance from where the picture was taken (in m.): ";
cin>>d;
cout<<"Size of the object in pixels: ";
cin>>op;
calc_length (d, op);
}
return 0;
}
Finding Measures from Digital Images
viernes, 20 de noviembre de 2015
martes, 17 de noviembre de 2015
Experiments to see what distance works better 2.0
We wanted to find out which distance was the best one in order to get better results. For the next four experiments we used this resolution: 2448 x 3264. We used this program to calculate the lengths:
#include <iostream>
using namespace std;
float lmc, lmp, lop, w, h;
void calc_length(float a, float b, double c){
double scale, loc;
scale= a/b; //We get how many centimeters a pixels is
loc= c*scale;
cout<<"The length of your object is of: "<<loc<<" cm. "<<loc*0.39370079<<" inches.";
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees, all of this using a digital picture with a marker information."<<endl<<endl;
cout<<"Tell me the length of your marker (in cm.): ";
cin>>lmc;
cout<<"Tell me the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me the length of your object (in pixels): ";
cin>>lop;
while(((lmp>=2448)&&(lmp>=3264))||((lop>=2448)&&(lop>=3264))){
cout<<"You are giving a pixel size of one of your objects bigger than your actual image, the objects you want to measure MUST be inside the image.\n";
cout<<"Tell me again the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me again the length of your object (in pixels): ";
cin>>lop;
}
calc_length(lmc, lmp, lop);//We still need to make the program to only show either measures or angles
}
This program to calculate de %error:
#include <iostream>
using namespace std;
float mr, mo, per;
int main() {
cout<<"Value of measure with ruler (real value): ";
cin>>mr;
cout<<"Value of measure obtained: ";
cin>>mo;
per=((mr-mo)/mr)*100;
cout<<"The error obtained was of: "<<per<<"%"<<endl<<endl;
return 0;
}
And from the following image:
We measured the red lines on the paper (one of 10 cm. and the other one of 25 cm.) and this area of the small agenda:
And we obtained the following results:
So now we now that if you get closer to the object you'll get better results.
*The biggest object in the image is the length from corner to corner
*Inclination of the camera of 0º with respect of the objects.
As conclusion, the closer you get to the image, the %error decreases. So we are now going to work with a distance of 1 meter away from our object.
lunes, 16 de noviembre de 2015
Program we used to calculate the % error
#include <iostream>
using namespace std;
float mr, mo, per;
int main() {
cout<<"Value of measure with ruler (real value): ";
cin>>mr;
cout<<"Value of measure obtained: ";
cin>>mo;
per=((mr-mo)/mr)*100;
cout<<"The error obtained was of: "<<per<<"%"<<endl<<endl;
return 0;
}
miércoles, 11 de noviembre de 2015
martes, 10 de noviembre de 2015
Which distance give us better results?
Experiments to evaluate distance
In order to find a distance that can give us better results with the camera that we are using, we did several experiments to see which one gave us a better answer. We are using always a resolution of 2448 x 3264.
To calculate the length of the object in the following five experiments we used this program:
And to calculate the % error we used the following program:
We used this picture:
To calculate the length of the object in the following five experiments we used this program:
#include <iostream>
using namespace std;
float lmc, lmp, lop, w, h;
void calc_length(float a, float b, double c){
double scale, loc;
scale= a/b; //We get how many centimeters a pixels is
loc= c*scale;
cout<<"The length of your object is of: "<<loc<<" cm. "<<loc*0.39370079<<" inches.";
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees, all of this using a digital picture with a marker information."<<endl<<endl;
cout<<"Tell me the length of your marker (in cm.): ";
cin>>lmc;
cout<<"Tell me the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me the length of your object (in pixels): ";
cin>>lop;
while(((lmp>=2448)&&(lmp>=3264))||((lop>=2448)&&(lop>=3264))){
cout<<"You are giving a pixel size of one of your objects bigger than your actual image, the objects you want to measure MUST be inside the image.\n";
cout<<"Tell me again the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me again the length of your object (in pixels): ";
cin>>lop;
}
calc_length(lmc, lmp, lop);//We still need to make the program to only show either measures or angles
}
And to calculate the % error we used the following program:
#include <iostream>
using namespace std;
float mr, mo, per;
int main() {
cout<<"Value of measure with ruler (real value): ";
cin>>mr;
cout<<"Value of measure obtained: ";
cin>>mo;
per=((mr-mo)/mr)*100;
cout<<"The error obtained was of: "<<per<<"%"<<endl<<endl;
return 0;
}
We used this picture:
1.-
Resolution: 2448 x 3264
Marker size: 21cm.- 476pixels.
Object size: 1405 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 1.4 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 3.08817 %
1 pixel :: 0.04411764 cm.
Object size: 1405 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 1.4 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 3.08817 %
1 pixel :: 0.04411764 cm.
2.-
Resolution: 2448 x 3264 pixels.
Marker size: 21cm.-318 pixels.
Object size: 919 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2 m.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 1.1478%
1 pixel :: 0.066038 cm.
Marker size: 21cm.-318 pixels.
Object size: 919 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2 m.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 1.1478%
1 pixel :: 0.066038 cm.
3.-
Resolution: 2448 x 3264
Marker size: 21cm.- 307pixels.
Object size: 901 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.15 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 2.7198%
1 pixel :: 0.0684039 cm.
Object size: 901 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.15 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 2.7198%
1 pixel :: 0.0684039 cm.
4.-
Resolution: 2448 x 3264
Marker size: 21cm.- 289 pixels.
Object size: 842 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.3 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 1.97233%
1 pixel :: 0.0726643 cm.
Object size: 842 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.3 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 1.97233%
1 pixel :: 0.0726643 cm.
5.-
Resolution: 2448 x 3264
Marker size: 21cm.- 254 pixels.
Object size: 746 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.6 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 2.79533%
1 pixel :: 0.0826771 cm.
Object size: 746 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2.6 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 2.79533%
1 pixel :: 0.0826771 cm.
After doing all these experiments, it seems that working 2 meters away from the image would be the best, which seems odd, because one would think that if you get closer to the image, one would get better results. Later on we'll do more experiments in order to prove or disprove this assumption.
Beginning Again (Lengths)
Resolution
After today classes we started to do new experiments, in order to accomplish all of the requirements. First we took the same picture with three different cameras (different resolutions) to see which one gave us a smaller error percentage.
The next four experiments were measured with the following program:
#include <iostream>
using namespace std;
float lmc, lmp, lop, w, h;
void calc_length(float a, float b, double c){
double scale, loc;
scale= a/b; //We get how many centimeters a pixels is
loc= c*scale;
cout<<"The length of your object is of: "<<loc<<" cm. "<<loc*0.39370079<<" inches.";
}
int main() {
cout<<"I give the lengths of an object in centimeters and inches, or angles in radians and degrees, all of this using a digital picture with a marker information."<<endl<<endl;
cout<<"What is the resolution of the image:\n";
cout<<"W: ";
cin>>w;
cout<<"H: ";
cin>>h;
cout<<"Tell me the length of your marker (in cm.): ";
cin>>lmc;
cout<<"Tell me the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me the length of your object (in pixels): ";
cin>>lop;
while(((lmp>=w)&&(lmp>=h))||((lop>=w)&&(lop>=h))){
cout<<"You are giving a pixel size of one of your objects bigger than your actual image, the objects you want to measure MUST be inside the image.\n";
cout<<"Tell me again the length of your marker (in pixels): ";
cin>>lmp;
cout<<"Tell me again the length of your object (in pixels): ";
cin>>lop;
}
calc_length(lmc, lmp, lop);//We still need to make the program to only show either measures or angles
}
To calculate the %error we used the following program:
#include <iostream>
using namespace std;
float mr, mo, per;
int main() {
cout<<"Value of measure with ruler (real value): ";
cin>>mr;
cout<<"Value of measure obtained: ";
cin>>mo;
per=((mr-mo)/mr)*100;
cout<<"The error obtained was of: "<<per<<"%"<<endl<<endl;
return 0;
}
The picture we used is this one:
1.-
Resolution: 1936 x 2592 pixels.
Marker size: 21cm.-256 pixels.
Object size: 754 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2 meters.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 3.086%
1 pixel :: 0.082031 cm
2.-
Resolution: 2448 x 3264 pixels.
Marker size: 21cm.-318 pixels.
Object size: 919 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2 m.
Actual size of the object I want to measure: 60 cm. - 23.62 inches.
%Error: 1.1478%
1 pixel :: 0.066038 cm.
3.-
Resolution: 720 x 960 pixels.
Marker size: 21cm.-115 pixels.
Object size: 342 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2m.
Actual size of the object I want to measure: 60 cm.- 23.62 inches.
%Error: 4.087%
1 pixel :: 0.182608
As our best experiment was #2 we decided to do another experiment to prove that we will get better results with that resolution (2448 x 3264 pixels). And this is the picture for that last experiment:
4.-
Resolution: 2448 x 3264 pixels.
Marker size: 21cm.-338 pixels.
Object size: 485 pixels.
Inclination of the camera of 0º with respect of the object.
Distance from the object: 2 m.
Actual size of the object I want to measure: 30 cm.- 11.8110 inches.
%Error: 0.44366%
1 pixel :: 0.062130 cm.
So we are going to keep working with this camera of 2448 x 3264 pixels. Because it gave us better results.
Suscribirse a:
Entradas (Atom)