Im trying to get working the Surface Matching Sample code from surface_matching. Im able to compile the code then when run with ./surface_matching /home/surface_matching/coke.ply /home/surface_matching/01.ply
Im running the same code sample as in the link. Code is the followving
#include "opencv2/surface_matching.hpp"
#include <iostream>
#include "opencv2/surface_matching/ppf_helpers.hpp"
#include "opencv2/core/utility.hpp"
using namespace std;
using namespace cv;
using namespace ppf_match_3d;
static void help(const string& errorMessage)
{
cout << "Program init error : "<< errorMessage << endl;
cout << "\nUsage : ppf_matching [input model file] [input scene file]"<< endl;
cout << "\nPlease start again with new parameters"<< endl;
}
int main(int argc, char** argv)
{
// welcome message
cout << "****************************************************" << endl;
cout << "* Surface Matching demonstration : demonstrates the use of surface matching"
" using point pair features." << endl;
cout << "* The sample loads a model and a scene, where the model lies in a different"
" pose than the training.\n* It then trains the model and searches for it in the"
" input scene. The detected poses are further refined by ICP\n* and printed to the "
" standard output." << endl;
cout << "****************************************************" << endl;
if (argc < 3)
{
help("Not enough input arguments");
exit(1);
}
#if (defined __x86_64__ || defined _M_X64)
cout << "Running on 64 bits" << endl;
#else
cout << "Running on 32 bits" << endl;
#endif
#ifdef _OPENMP
cout << "Running with OpenMP" << endl;
#else
cout << "Running without OpenMP and without TBB" << endl;
#endif
string modelFileName = (string)argv[1];
string sceneFileName = (string)argv[2];
Mat pc = loadPLYSimple(modelFileName.c_str(), 1);
// Now train the model
cout << "Training..." << endl;
int64 tick1 = cv::getTickCount();
ppf_match_3d::PPF3DDetector detector(0.025, 0.05);
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
cout << endl << "Training complete in "
<< (double)(tick2-tick1)/ cv::getTickFrequency()
<< " sec" << endl << "Loading model..." << endl;
// Read the scene
Mat pcTest = loadPLYSimple(sceneFileName.c_str(), 1);
// Match the model to the scene and get the pose
cout << endl << "Starting matching..." << endl;
vector<Pose3DPtr> results;
tick1 = cv::getTickCount();
// orig detector.match(pcTest, results, 1.0/40.0, 0.05);
detector.match(pcTest, results, 1.0/40.0, 0.05);
tick2 = cv::getTickCount();
cout << endl << "PPF Elapsed Time " <<
(tick2-tick1)/cv::getTickFrequency() << " sec" << endl;
// Get only first N results
int N = 2;
vector<Pose3DPtr> resultsSub(results.begin(),results.begin()+N);
// Create an instance of ICP
ICP icp(100, 0.005f, 2.5f, 8);
int64 t1 = cv::getTickCount();
// Register for all selected poses
cout << endl << "Performing ICP on " << N << " poses..." << endl;
icp.registerModelToScene(pc, pcTest, resultsSub);
int64 t2 = cv::getTickCount();
cout << endl << "ICP Elapsed Time " <<
(t2-t1)/cv::getTickFrequency() << " sec" << endl;
cout << "Poses: " << endl;
// debug first five poses
for (size_t i=0; i<resultsSub.size(); i++)
{
Pose3DPtr result = resultsSub[i];
cout << "Pose Result " << i << endl;
result->printPose();
if (i==0)
{
Mat pct = transformPCPose(pc, result->pose);
writePLY(pct, "para6700PCTrans.ply");
}
}
return 0;
}
It runs but never gets any results. I got this error
$ ./surface_matching /home/admini/surface_matching/coke.ply /home/admini/surface_matching/01.ply
****************************************************
* Surface Matching demonstration : demonstrates the use of surface matching using point pair features.
* The sample loads a model and a scene, where the model lies in a different pose than the training.
* It then trains the model and searches for it in the input scene. The detected poses are further refined by ICP
* and printed to the standard output.
****************************************************
Running on 64 bits
Running without OpenMP and without TBB
Training...
Training complete in 0.100169 sec
Loading model...
Starting matching...
Segmentation fault (core dumped)
Training is complete and starts matching but then Segmentation fault. What can be the problem? Here the object model file:
And the scene file
What can be the problem?
Related
I am studying 3d point cloud and I am using opencv surface matchig module But I have an error I cant understand
My code is :
#include "stdafx.h"
#include <iostream>
#include <vector>
#include "opencv2/core/utility.hpp"
#include "opencv2\opencv_modules.hpp"
#include "opencv2\surface_matching.hpp"
#include "opencv2\surface_matching\ppf_helpers.hpp"
using namespace std;
using namespace cv;
using namespace cv::ppf_match_3d;
static void help(const string& errorMessage)
{
cout << "Program init error : " << errorMessage << endl;
cout << "\nUsage : ppf_matching [input model file] [input scene file]" << endl;
cout << "\nPlease start again with new parameters" << endl;
}
int main(int argc, char** argv)
{
// welcome message
cout << "****************************************************" << endl;
cout << "* Surface Matching demonstration : demonstrates the use of surface matching"
" using point pair features." << endl;
cout << "* The sample loads a model and a scene, where the model lies in a different"
" pose than the training.\n* It then trains the model and searches for it in the"
" input scene. The detected poses are further refined by ICP\n* and printed to the "
" standard output." << endl;
cout << "****************************************************" << endl;
/* if (argc < 2)
{
help("Not enough input arguments");
exit(1);
}*/
/*#if (defined __x86_64__ || defined _M_X64)
cout << "Running on 64 bits" << endl;
#else
cout << "Running on 32 bits" << endl;
#endif
#ifdef _OPENMP
cout << "Running with OpenMP" << endl;
#else
cout << "Running without OpenMP and without TBB" << endl;
#endif*/
string modelFileName = "C://opencv_contrib-master//modules//surface_matching//samples//data//parasaurolophus_6700";
string sceneFileName = "C://opencv_contrib-master//modules//surface_matching//samples//data//parasaurolophus_low_normals2";
Mat pc = loadPLYSimple(modelFileName.c_str(), 1);
// Now train the model
cout << "Training..." << endl;
int64 tick1 = cv::getTickCount();
ppf_match_3d::PPF3DDetector detector(0.025, 0.05);
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
cout << endl << "Training complete in "
<< (double)(tick2 - tick1) / cv::getTickFrequency()
<< " sec" << endl << "Loading model..." << endl;
// Read the scene
Mat pcTest = loadPLYSimple(sceneFileName.c_str(), 1);
// Match the model to the scene and get the pose
cout << endl << "Starting matching..." << endl;
vector<Pose3DPtr> results;
tick1 = cv::getTickCount();
detector.match(pcTest, results, 1.0 / 40.0, 0.05);
tick2 = cv::getTickCount();
cout << endl << "PPF Elapsed Time "
<< (tick2 - tick1) / cv::getTickFrequency() << " sec" << endl;
// Get only first N results
int N = 2;
vector<Pose3DPtr> resultsSub(results.begin(), results.begin() + N);
// Create an instance of ICP
ICP icp(100, 0.005f, 2.5f, 8);
int64 t1 = cv::getTickCount();
// Register for all selected poses
cout << endl << "Performing ICP on " << N << " poses..." << endl;
icp.registerModelToScene(pc, pcTest, resultsSub);
int64 t2 = cv::getTickCount();
cout << endl << "ICP Elapsed Time "
<< (t2 - t1) / cv::getTickFrequency() << " sec" << endl;
cout << "Poses: " << endl;
// debug first five poses
for (size_t i = 0; i<resultsSub.size(); i++)
{
Pose3DPtr result = resultsSub[i];
cout << "Pose Result " << i << endl;
result->printPose();
if (i == 0)
{
Mat pct = transformPCPose(pc, result->pose);
writePLY(pct, "para6700PCTrans.ply");
}
}
return 0;
}
And my error :(when code was these line :
detector.trainModel(pc);
int64 tick2 = cv::getTickCount();
I get this error:
Use debug mode. Change Key type at t_hash_int.cpp source file by these lines
#if (defined x86_64 || defined _M_X64)
typedef uint64_t KeyType;
#else
typedef unsigned int KeyType;
#endif
Build again from the source
Check this issue: https://github.com/opencv/opencv_contrib/issues/170
It seems that you use the release mode to run the program.
I have meet this problem before. When I change to debug mode. Everything works well.
I'm trying to import facial landmark points from webcam or video
using dlib into a file . I can display all detected landmarks on the terminal
but it is only saving the first and second landmark ponits (x,y) into the
output file , and not saving all the detected landmarks into
the output file
#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
using namespace dlib;
using namespace std;
int main()
{
try
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
image_window win;
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
while(!win.is_closed())
{
// Grab a frame
cv::Mat temp;
cap >> temp;
cv_image<bgr_pixel> cimg(temp);
std::vector<rectangle> faces = detector(cimg);
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
{
full_object_detection shape = pose_model(cimg, faces[i]);
cout << "number of parts: "<< shape.num_parts() << endl;
cout << "pixel position of first part: " << shape.part(0) << endl;
cout << "pixel position of second part: " << shape.part(1) << endl;
shapes.push_back(pose_model(cimg, faces[i]));
const full_object_detection& d = shapes[0];
ofstream outputfile;
outputfile.open("data1.txt");
outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl;
outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl;
}
win.clear_overlay();
win.set_image(cimg);
win.add_overlay(render_face_detections(shapes));
}
}
catch(serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
Am I wrong or you want to save all landmarks when you have only:
ofstream outputfile;
outputfile.open("data1.txt");
outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl;
outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl;
And even not closing the file correctly. Try with for statement.
Hi I'm working with GPS output. To be more accurate I'm working using the $GPRMC output. Now the output that I get is in the following form:
$GPRMC,225446,A,4916.45 N,12311.12 W,000.5,054.7,191194,020.3 E,*68"
This output constitutes of time, lats, longs, speed in knots, info about course, date, magnetic variation and mandatory checksum.
The image that I have attached shows the current result I'm getting as I'm taking out the sub strings from the string.
Now I'm getting the time in the hhmmss format. I want it in hh:mm:ss format.
Plus I'm getting the longitude as 4916.45 N. I want to get it as 49 degrees 16' 45".
And the latitude as 123 degrees 11' 12". I'm a beginner so I really don't know how to convert the format. I have also attached my code below.
#include<iostream>
#include<string>
#include<sstream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
std::string input = "$GPRMC,225446,A,4916.45 N,12311.12 W,000.5,054.7,191194,020.3 E,*68";
std::istringstream ss(input);
std::string token;
string a[10];
int n = 0;
while (std::getline(ss, token, ','))
{
//std::cout << token << '\n';
a[n] = token;
n++;
}
cout << a[0] << endl << endl;
cout << "Time=" << a[1] << endl << endl;
cout << "Navigation receiver status:" << a[2] << endl << endl;
cout << "Latitude=" << a[3] << endl << endl;
cout << "Longitude=" << a[4] << endl << endl;
cout << "Speed over ground knots:" << a[5] << endl << endl;
cout << "Course made good,True:" << a[6] << endl << endl;
cout << "Date of Fix:" << a[7] << endl << endl;
cout << "Magnetic variation:" << a[8] << endl << endl;
cout << "Mandatory Checksum:" << a[9] << endl << endl;
_getch();
return 0;
}
First thing is that your NMEA sentence is wrong, there should be commas ',' before N and W, so you will actually have to parse "12311.12" and not "12311.12 W". You can check it on this site: http://aprs.gids.nl/nmea/#rmc, you should also always check checksum of sentence - for online checks use: http://www.hhhh.org/wiml/proj/nmeaxor.html.
To parse longitude and latitude I suggest regexps, I am notsaying this is regexp is correct - it only parses data you have provided:
#include <iostream>
#include <string>
#include <regex>
#include <iostream>
std::tuple<int,int,int> parseLonLat(const std::string& s) {
std::regex pattern("(\\d{2,3})(\\d+{2})\\.(\\d+{2})" );
// Matching single string
std::smatch sm;
if (std::regex_match(s, sm, pattern)) {
return std::make_tuple(std::stoi(sm[1]), std::stoi(sm[2]), std::stoi(sm[3]));
}
return std::make_tuple(-1,-1,-1);
}
int main (int argc, char** argv) {
auto loc1 = parseLonLat("4916.45");
std::cout << std::get<0>(loc1) << ", " << std::get<1>(loc1) << ", " << std::get<2>(loc1) << "\n";
// output: 49, 16, 45
auto loc2 = parseLonLat("12311.12");
std::cout << std::get<0>(loc2) << ", " << std::get<1>(loc2) << ", " << std::get<2>(loc2) << "\n";
// output: 123, 11, 12
}
http://coliru.stacked-crooked.com/a/ce6bdb1e551df8b5
You'll have to parse that yourself; there's no GPS parsing in standard C++.
You may want to write your own Angle class in order to have 49 degrees 16' 45" as possible output. You'll want to overload operator<< for that.
I've computed a 2D constrained delaunay triangulation from 2.5D data using the projection_traits_xy_3 [1]. Now I would like to get a mesh that I can visualize.
I've managed to do that with 3d delaunay following the manual[2], how could I achieve it with a 2.5D CDT ?
[...]
typedef CGAL::Projection_traits_xy_3<K> Gt;
typedef CGAL::Constrained_Delaunay_triangulation_2<Gt, Tds> CDT;
[...]
CDT cdt;
cdt.insert(points.begin(),points.end());
[...]
¿?
[...]
std::ofstream out(outdir + "out.off");
Polyhedron output_mesh;
CGAL::output_surface_facets_to_polyhedron(¿?, output_mesh);
out << output_mesh;
[1] http://pastebin.com/HzAwrnW5
[2] http://doc.cgal.org/latest/Point_set_processing_3/index.html#chappoint_set_processing_3
http://doc.cgal.org/latest/Surface_reconstruction_points_3/
Here comes pseudocode forwriting it into an off file
cout << "OFF\n" << cdt.number_of_vertices()
<< " " << cdt.number_of_faces() << " 0" << std::endl;
std::map<vertex_handle,int> indices;
int counter = 0;
for all finite vertices v {
cout << v->point() <<std::endl;
indices.insert(v, counter++);
}
for all finite faces f {
cout << "3 " << indices[f->vertex(0)]
<< " " << indices[f->vertex(1)]
<< " " << indices[f->vertex(2)] << std::endl;
}
From #Andreas suggestion:
Here comes the code for writing it into an off file
std::ofstream outstream("output.off");
outstream << "OFF\n" << cdt.number_of_vertices()
<< " " << cdt.number_of_faces() << " 0" << std::endl;
std::map<CDT::Vertex_handle,int> indices;
int counter = 0;
for(CDT::Finite_vertices_iterator it = cdt.finite_vertices_begin(); it != cdt.finite_vertices_end(); ++it)
{
outstream << it->point() << std::endl;
indices.insert(std::pair<CDT::Vertex_handle,int>(it, counter++));
}
for(CDT::Finite_faces_iterator it = cdt.finite_faces_begin(); it != cdt.finite_faces_end(); ++it)
{
outstream << "3 " << indices[it->vertex(0)]
<< " " << indices[it->vertex(1)]
<< " " << indices[it->vertex(2)] << std::endl;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I was doing an assignment for my subject here and in the assignment, every student is required to create a simple C++ program. The problem here is, when I do not assign a default to a variable, a compile error will occur. However, when I assign a default value (in this case, value = 0), the value will always be 0.
My question is, is there any way to solve this problem while not encountering the compile error?
If there was a similar question asked, could you please also, include the link to the solved question as well? Thank you very much!
[Edit #1: To those who wonder why the code is "messy", I only used simple commands and did not use object oriented components, if/else statements etc. The project created was meant to be composed of "simple codes".]
[Edit #2: This is the output display that I snapped:
http://i.imgur.com/4csk1Rz.png
The Total Discounted fee part should be displaying numbers instead of default value 0]
(Microsoft Visual Studio Pro 2013; C++)
Expected output display:
http://i.imgur.com/jOJvymV.png
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
/* Declare variables */
int qtyVehicleCar, qtyVehicleTaxi, qtyVehicleTruck; // User input
double feeOriginalCar, feeTotalOriginalCar, rateDiscountCar, feeTotalDiscountedCar, feeTotalAfterDiscountedCar; // variables for vehicle Car
double feeOriginalTaxi, feeTotalOriginalTaxi, rateDiscountTaxi, feeTotalDiscountedTaxi, feeTotalAfterDiscountedTaxi; // variables for vehicle Taxi
double feeOriginalTruck, feeTotalOriginalTruck, rateDiscountTruck, feeTotalDiscountedTruck, feeTotalAfterDiscountedTruck; // variables for vehicle Truck
double feeRepTotalOriginalFee, feeRepTotalDiscountedFee, feeRepTotalAfterDiscounted; // Generate final output
cout << "=====================================\n";
cout << "=====================================\n";
cout << "====== Malaysia Highway Company =====\n";
cout << "=====================================\n";
cout << "=====================================\n";
cout << endl;
cout << "Enter quantity of the vehicles on 1st January 2014: " << endl;
cout << "Car\t\t:\t";
cin >> qtyVehicleCar;
cout << "Taxi\t\t:\t";
cin >> qtyVehicleTaxi;
cout << "Truck\t\t:\t";
cin >> qtyVehicleTruck;
/* Lay out the Report table */
cout << endl << endl << endl;
cout << "Report\n";
cout << "--------\n";
cout << endl;
/* ============================== */
/* Declaration prior to process */
/* ============================== */
/* The problematic part
feeTotalDiscountedCar = 0;
feeTotalDiscountedTaxi = 0;
feeTotalDiscountedTaxi = 0;
*/
// Prices
feeOriginalCar = 2.00;
feeOriginalTaxi = 1.00;
feeOriginalTruck = 3.50;
feeTotalOriginalCar = feeOriginalCar * qtyVehicleCar;
feeTotalOriginalTaxi = feeOriginalTaxi * qtyVehicleTaxi;
feeTotalOriginalTruck = feeOriginalTruck * qtyVehicleTruck;
// In percentage
rateDiscountCar = 2;
rateDiscountTaxi = 10;
rateDiscountTruck = 15;
feeTotalAfterDiscountedCar = (rateDiscountCar/100) * feeTotalOriginalCar;
feeTotalAfterDiscountedTaxi = (rateDiscountTaxi/100) * feeTotalOriginalTaxi;
feeTotalAfterDiscountedTruck = (rateDiscountTruck/100) * feeTotalOriginalTruck;
// Final total - to be displayed
feeTotalAfterDiscountedCar = feeTotalOriginalCar - feeTotalAfterDiscountedCar;
feeTotalAfterDiscountedTaxi = feeTotalOriginalTaxi - feeTotalAfterDiscountedTaxi;
feeTotalOriginalTruck = feeTotalOriginalTruck - feeTotalAfterDiscountedTruck;
feeRepTotalOriginalFee = feeTotalOriginalCar + feeTotalOriginalTaxi + feeTotalOriginalTruck;
feeRepTotalDiscountedFee = feeTotalDiscountedCar + feeTotalAfterDiscountedTaxi + feeTotalAfterDiscountedTruck;
feeRepTotalAfterDiscounted = feeRepTotalOriginalFee - feeRepTotalDiscountedFee;
/* ================= */
/* Declaration END */
/* ================= */
/* Gives the following variables a default value, they will be modified later by the program */
feeTotalAfterDiscountedTruck = 0;
feeTotalDiscountedTruck = 0;
/* Processes */
cout << "Item\t\t\t\t" << "Car\t" << "Taxi\t" << "Truck\t" << endl;
cout << "------------------------------------------------------\n";
cout << "Original fee\t\t\t" << "RM " << feeOriginalCar << "\t" << "RM " << feeOriginalTaxi << "\t" << "RM " << feeOriginalTruck << endl;
cout << "Quantity\t\t\t" << qtyVehicleCar << "\t" << qtyVehicleTaxi << "\t" << qtyVehicleTruck << endl;
cout << "Total original fee\t\t" << "RM " << feeOriginalCar << "\t" << "RM " << feeOriginalTaxi << "\t" << "RM " << feeOriginalTruck << endl;
cout << "Discount rate\t\t\t" << rateDiscountCar << "%\t" << rateDiscountTaxi << "%\t" << rateDiscountTruck << "%\t" << endl;
cout << "Total discounted fee\t\t" << "RM " << feeTotalDiscountedCar << "\t" << "RM " << feeTotalDiscountedTaxi << "\t" << "RM " << feeTotalDiscountedTruck << endl;
cout << "Total after discounted fee\t" << "RM " << feeTotalAfterDiscountedCar << "\t" << "RM " << feeTotalAfterDiscountedTaxi << "\t" << "RM " << feeTotalAfterDiscountedTruck << endl;
cout << endl;
/* Displays output */
cout << "Total original fee\t\t:\t" << "RM " << feeRepTotalOriginalFee << endl;
cout << "Total discounted fee\t\t:\t" << "RM " << feeRepTotalDiscountedFee << endl;
cout << "Total after discounted fee\t:\t" << "RM " << feeRepTotalAfterDiscounted << endl;
cout << endl << endl;
/* Displays end line */
cout << "------------------- End of Program -------------------" << endl;
system("PAUSE");
return 0;
}
An uninitialized variables warning can mean either (1) you forgot to initialize something or (2) you thought you initialized it but didn't. Looks to me that in this case it's the second problem. Your variable names are mixed up.
For example,
feeTotalAfterDiscountedCar = (rateDiscountCar/100) * feeTotalOriginalCar;
feeTotalAfterDiscountedTaxi = (rateDiscountTaxi/100) * feeTotalOriginalTaxi;
feeTotalAfterDiscountedTruck = (rateDiscountTruck/100) * feeTotalOriginalTruck;
These are supposed to be the amounts of the discounts, no? So why are you storing them into feeTotalAfterDiscountedSomething rather than feeTotalDiscountedSomething?
Similarly,
feeTotalAfterDiscountedCar = feeTotalOriginalCar - feeTotalAfterDiscountedCar;
feeTotalAfterDiscountedTaxi = feeTotalOriginalTaxi - feeTotalAfterDiscountedTaxi;
feeTotalOriginalTruck = feeTotalOriginalTruck - feeTotalAfterDiscountedTruck;
Why is the third one storing the result into feeTotalOriginalTruck instead of feeTotalAfterDiscountedTruck? (Note also that if you fix the first problem above, the rhs of the subtraction will also need to change).
Also,
feeRepTotalDiscountedFee = feeTotalDiscountedCar + feeTotalAfterDiscountedTaxi + feeTotalAfterDiscountedTruck;
Similar problem. These should, I believe, all be feeTotalDiscountedSomething rather than feeTotalAfterDiscountedSomething.
The compiler rightfully complains that feeTotalDiscountedCar and feeTotalDiscountedTaxi are uninitialized. You need to initialize them somewhere. Maybe you want the user to enter them somewhere like this:
cout << "Discount Fee Total Taxi:";
cin >> feeTotalDiscountedTaxi;
cout << "Discount Fee Total Car:";
cin >> feeTotalDiscountedCar;
why are you setting them to zero just before printing out?
feeTotalAfterDiscountedTruck = 0;
feeTotalDiscountedTruck = 0;
It will show the error because you are trying to use the variable with out initializing it.