$search
00001 00005 #include "tools.hpp" 00006 00007 void writePoints(const char *filename, const vector<Point2f>& pts) { 00008 00009 ofstream myfile; 00010 myfile.open(filename); 00011 00012 for (unsigned int jjj = 0; jjj < pts.size(); jjj++) { 00013 myfile << pts.at(jjj).x << "," << pts.at(jjj).y << endl; 00014 } 00015 00016 myfile.close(); 00017 00018 } 00019 00020 void readPoints(const char *filename, vector<Point2f>& pts) { 00021 00022 pts.clear(); 00023 ifstream myfile; 00024 myfile.open(filename); 00025 00026 char buffer[512]; 00027 00028 Point2f latestPoint; 00029 char comma; 00030 00031 while (true) { 00032 00033 comma = ' '; 00034 myfile.getline(buffer, 512); 00035 00036 stringstream ss; 00037 00038 ss << buffer; 00039 00040 ss >> latestPoint.x >> comma >> latestPoint.y; 00041 00042 if (comma == ',') { 00043 pts.push_back(latestPoint); 00044 } else { 00045 break; 00046 } 00047 00048 00049 if (myfile.eof()) { 00050 break; 00051 } 00052 } 00053 00054 00055 myfile.close(); 00056 00057 } 00058 00059 double lookupValue(double xi, double yi, double maxVal, const Mat& lookupMat) { 00060 00061 00062 Point2f coord(xi*((float) lookupMat.cols)/maxVal, yi*((float) lookupMat.rows)/maxVal); 00063 00064 double d = getInterpolatedVal(lookupMat, coord); 00065 00066 //printf("%s << interpolating (%f, %f) -> (%f)\n", __FUNCTION__, coord.x, coord.y, d); 00067 00068 /* 00069 double vx = (xi / maxVal) * lookupMat.cols; 00070 double vy = (yi / maxVal) * lookupMat.rows; 00071 00072 int index_1 = std::max(std::min(((int) vy), lookupMat.rows), 0); 00073 int index_2 = std::max(std::min(((int) vx), lookupMat.cols), 0); 00074 00075 double d = lookupMat.at<double>(index_1, index_2); 00076 */ 00077 00078 return d; 00079 00080 } 00081 00082 double getInterpolatedVal(const Mat& img, Point2f& coord) { 00083 00084 double retVal = 0.00; 00085 00086 00087 00088 // Find four neighbours 00089 Point dcoord[4]; 00090 float val[4]; 00091 float dist[4], total_dist = 0.0; 00092 00093 val[0] = 0.0; 00094 val[1] = 0.0; 00095 val[2] = 0.0; 00096 val[3] = 0.0; 00097 00098 //printf("%s << coord = (%f, %f)\n", __FUNCTION__, coord.x, coord.y); 00099 00100 // #1: 00101 dcoord[0] = Point(floor(coord.x), floor(coord.y)); 00102 00103 if (img.type() == CV_8UC1) { 00104 val[0] = img.at<unsigned char>(dcoord[0].y, dcoord[0].x); 00105 } else if (img.type() == CV_64FC1) { 00106 val[0] = img.at<double>(dcoord[0].y, dcoord[0].x); 00107 } 00108 00109 00110 dist[0] = pow(pow(coord.x - ((float) dcoord[0].x), 2.0) + pow(coord.y - ((float) dcoord[0].y), 2.0), 0.5); 00111 total_dist += dist[0]; 00112 //printf("%s << coord[0] = (%d, %d); (%f); (%f)\n", __FUNCTION__, dcoord[0].x, dcoord[0].y, val[0], dist[0]); 00113 00114 // #2: 00115 dcoord[1] = Point(ceil(coord.x), floor(coord.y)); 00116 00117 if (img.type() == CV_8UC1) { 00118 val[1] = img.at<unsigned char>(dcoord[1].y, dcoord[1].x); 00119 } else if (img.type() == CV_64FC1) { 00120 val[1] = img.at<double>(dcoord[1].y, dcoord[1].x); 00121 } 00122 00123 00124 00125 00126 dist[1] = pow(pow(coord.x - ((float) dcoord[1].x), 2.0) + pow(coord.y - ((float) dcoord[1].y), 2.0), 0.5); 00127 total_dist += dist[1]; 00128 //printf("%s << coord[1] = (%d, %d); (%f); (%f)\n", __FUNCTION__, dcoord[1].x, dcoord[1].y, val[1], dist[1]); 00129 00130 // #3: 00131 dcoord[2] = Point(ceil(coord.x), ceil(coord.y)); 00132 00133 if (img.type() == CV_8UC1) { 00134 val[2] = img.at<unsigned char>(dcoord[2].y, dcoord[2].x); 00135 } else if (img.type() == CV_64FC1) { 00136 val[2] = img.at<double>(dcoord[2].y, dcoord[2].x); 00137 } 00138 00139 00140 dist[2] = pow(pow(coord.x - ((float) dcoord[2].x), 2.0) + pow(coord.y - ((float) dcoord[2].y), 2.0), 0.5); 00141 total_dist += dist[2]; 00142 //printf("%s << coord[2] = (%d, %d); (%f); (%f)\n", __FUNCTION__, dcoord[2].x, dcoord[2].y, val[2], dist[2]); 00143 00144 // #4: 00145 dcoord[3] = Point(floor(coord.x), ceil(coord.y)); 00146 00147 if (img.type() == CV_8UC1) { 00148 val[3] = img.at<unsigned char>(dcoord[3].y, dcoord[3].x); 00149 } else if (img.type() == CV_64FC1) { 00150 val[3] = img.at<double>(dcoord[3].y, dcoord[3].x); 00151 } 00152 00153 00154 dist[3] = pow(pow(coord.x - ((float) dcoord[3].x), 2.0) + pow(coord.y - ((float) dcoord[3].y), 2.0), 0.5); 00155 total_dist += dist[3]; 00156 //printf("%s << coord[3] = (%d, %d); (%f); (%f)\n", __FUNCTION__, dcoord[3].x, dcoord[3].y, val[3], dist[3]); 00157 00158 //printf("%s << (%f, %f, %f, %f) : (%f, %f, %f, %f) : (%f)\n", __FUNCTION__, val[0], val[1], val[2], val[3], dist[0], dist[1], dist[2], dist[3], total_dist); 00159 00160 Point ref_coord = Point(floor(coord.x), floor(coord.y)); 00161 00162 if (total_dist == 0.0) { 00163 retVal = val[0]; 00164 //printf("%s << returning reference val...\n", __FUNCTION__); 00165 //printf("%s << (%f, %f, %f, %f) : (%f, %f) vs (%d, %d) : (%f)\n", __FUNCTION__, val[0], val[1], val[2], val[3], coord.x, coord.y, ref_coord.x, ref_coord.y, retVal); 00166 return retVal; 00167 } 00168 00169 00170 00171 Mat x_mat(1, 2, CV_64FC1); 00172 x_mat.at<double>(0,0) = 1 - abs(coord.x - ((double) ref_coord.x)); 00173 x_mat.at<double>(0,1) = abs(coord.x - ((double) ref_coord.x)); 00174 00175 Mat y_mat(2, 1, CV_64FC1); 00176 y_mat.at<double>(0,0) = 1 - abs(coord.y - ((double) ref_coord.y)); 00177 y_mat.at<double>(1,0) = abs(coord.y - ((double) ref_coord.y)); 00178 00179 Mat f_vals(2, 2, CV_64FC1); 00180 f_vals.at<double>(0,0) = val[0]; 00181 f_vals.at<double>(0,1) = val[3]; 00182 f_vals.at<double>(1,0) = val[1]; 00183 f_vals.at<double>(1,1) = val[2]; 00184 00185 00186 00187 Mat A = x_mat * f_vals * y_mat; 00188 00189 retVal = A.at<double>(0,0); 00190 00191 if (0) { // (img.type() == CV_64FC1) { 00192 cout << "x_mat = " << x_mat << endl; 00193 cout << "y_mat = " << y_mat << endl; 00194 cout << "f_vals = " << f_vals << endl; 00195 cout << "A = " << A << endl; 00196 00197 printf("%s << vals: (%f, %f, %f, %f) : dists: (%f, %f, %f, %f) : (%f, %f) vs (%d, %d) : (%f)\n", __FUNCTION__, val[0], val[1], val[2], val[3], dist[0], dist[1], dist[2], dist[3], coord.x, coord.y, ref_coord.x, ref_coord.y, retVal); 00198 00199 cin.get(); 00200 } 00201 00202 00203 00204 00205 00206 00207 00208 00209 return retVal; 00210 00211 00212 } 00213 00214 void convertUcharToBinary(unsigned char val, int* binaryArray) { 00215 for (int iii = 0; iii < 8; iii++) { 00216 if ((int) val >= (int) pow(2, 7-iii)) { 00217 binaryArray[iii] = 1; 00218 val -= (int) pow(2, 7-iii); 00219 } else { 00220 binaryArray[iii] = 0; 00221 } 00222 } 00223 } 00224 00225 int countElementsInFolder(const char* folderName, vector<string>& elementNames, int elementType) { 00226 int elementCount = 0; 00227 DIR *dirp; 00228 struct dirent * entry; 00229 00230 int typeCode = 0; 00231 00232 if (elementType == 0) { 00233 // Wants to count files 00234 typeCode = DT_REG; 00235 } else if (elementType == 1) { 00236 // Wants to count folders 00237 typeCode = DT_DIR; 00238 } 00239 00240 char *folder; 00241 00242 folder = (char*) malloc(strlen(folderName) + 32); 00243 sprintf(folder, "%s", folderName); 00244 00245 //printf("%s << folder = %s\n", __FUNCTION__, folder); 00246 00247 dirp = opendir(folder); 00248 00249 //printf("%s << folder opened.\n", __FUNCTION__); 00250 00251 while ((entry = readdir(dirp)) != NULL) { 00252 //printf("%s << entry is: %s\n", __FUNCTION__, entry->d_name); 00253 if ((entry->d_type == typeCode) && (entry->d_name[0] != '.')) { // If the entry is a regular folder 00254 00255 elementNames.push_back(string(entry->d_name)); 00256 00257 00258 printf("%s << elementName[%d] = %s\n", __FUNCTION__, elementCount, elementNames.at(elementCount).c_str()); 00259 00260 elementCount++; 00261 00262 } 00263 } 00264 00265 closedir(dirp); 00266 00267 return elementCount; 00268 00269 } 00270 00271 void redistortPoints(const vector<Point2f>& src, vector<Point2f>& dst, const Mat& cameraMatrix, const Mat& distCoeffs, const Mat& newCamMat) { 00272 00273 double fx, fy, ifx, ify, cx, cy; 00274 double fx0, fy0, ifx0, ify0, cx0, cy0; 00275 double k[8]={0,0,0,0,0,0,0,0}; //, RR[3][3]={{1,0,0},{0,1,0},{0,0,1}}; 00276 double r2, icdist, deltaX, deltaY; 00277 double x, y, x0, y0, x1, y1; //, xx, yy, ww; 00278 00279 Mat optimalMat(3, 3, CV_64FC1); 00280 00281 // optimalMat = getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, Size(640,48), 1.0); 00282 00283 //printf("%s << entered function.\n", __FUNCTION__); 00284 00285 // will probably crash if it receives the identity matrix etc... 00286 00287 fx0 = cameraMatrix.at<double>(0, 0); 00288 fy0 = cameraMatrix.at<double>(1, 1); 00289 ifx0 = 1./fx0; 00290 ify0 = 1./fy0; 00291 cx0 = cameraMatrix.at<double>(0, 2); 00292 cy0 = cameraMatrix.at<double>(1, 2); 00293 00294 fx = newCamMat.at<double>(0, 0); 00295 fy = newCamMat.at<double>(1, 1); 00296 ifx = 1./fx; 00297 ify = 1./fy; 00298 cx = newCamMat.at<double>(0, 2); 00299 cy = newCamMat.at<double>(1, 2); 00300 00301 for (unsigned int i = 0; i < 8; i++){ 00302 k[i] = distCoeffs.at<double>(0, i); 00303 } 00304 00305 //printf("%s << cx = %f; cy = %f\n", __FUNCTION__, cx, cy); 00306 00307 //cin.get(); 00308 00309 dst.clear(); 00310 00311 for (unsigned int i = 0; i < src.size(); i++) { 00312 // Points in undistorted image 00313 x = src.at(i).x; 00314 y = src.at(i).y; 00315 00316 // printf("%s << undistorted points at [%d] = (%f, %f)\n", __FUNCTION__, i, x, y); 00317 00318 // Apply cameraMatrix parameters (normalization) 00319 x0 = (x - cx)*ifx; 00320 y0 = (y - cy)*ify; 00321 00322 x = x0; 00323 y = y0; 00324 00325 // Determine radial and tangential distances/factors 00326 r2 = x*x + y*y; 00327 icdist = (1 + ((k[7]*r2 + k[6])*r2 + k[5])*r2)/(1 + ((k[4]*r2 + k[1])*r2 + k[0])*r2); 00328 deltaX = 2*k[2]*x*y + k[3]*(r2 + 2*x*x); 00329 deltaY = k[2]*(r2 + 2*y*y) + 2*k[3]*x*y; 00330 00331 //icdist *= 0.75; 00332 00333 // Redistort 00335 //x = (x0 - deltaX)/icdist; 00336 //y = (y0 - deltaY)/icdist; 00337 //*/ 00339 x = (x0/icdist) + deltaX; 00340 y = (y0/icdist) + deltaY; 00341 //*/ 00342 //x = x0/icdist; 00343 //y = y0/icdist; 00344 00345 // Do something... 00346 /* 00347 xx = RR[0][0]*x + RR[0][1]*y + RR[0][2]; 00348 yy = RR[1][0]*x + RR[1][1]*y + RR[1][2]; 00349 ww = 1./(RR[2][0]*x + RR[2][1]*y + RR[2][2]); 00350 x = xx*ww; 00351 y = yy*ww; 00352 */ 00353 00354 x1 = x; 00355 y1 = y; 00356 00357 // Reverse cameraMatrix parameters (denormalization) 00358 x = (x1/ifx0) + cx0; 00359 y = (y1/ify0) + cy0; 00360 00361 // printf("%s << redistorted points at [%d] = (%f, %f)\n", __FUNCTION__, i, x, y); 00362 00363 //cin.get(); 00364 00365 dst.push_back(Point2f(x, y)); 00366 } 00367 00368 // Temporary... 00369 // dst.assign(src.begin(), src.end()); 00370 } 00371 00372 double timeElapsedMS(struct timeval& timer, bool reset) { 00373 00374 struct timeval new_time; 00375 00376 long seconds, useconds; 00377 00378 gettimeofday(&new_time, NULL); 00379 00380 seconds = new_time.tv_sec - timer.tv_sec; 00381 useconds = new_time.tv_usec - timer.tv_usec; 00382 00383 double retVal = ((double) seconds) * 1000.0 + ((double) useconds) * 0.001; 00384 00385 if (reset) { 00386 timer = new_time; 00387 } 00388 00389 return retVal; 00390 00391 00392 } 00393 00394 bool matricesAreEqual(Mat& mat1, Mat& mat2) { 00395 00396 if (mat1.rows != mat2.rows) { 00397 return false; 00398 } 00399 00400 if (mat1.cols != mat2.cols) { 00401 return false; 00402 } 00403 00404 if (mat1.type() != mat2.type()) { 00405 return false; 00406 } 00407 00408 if ((mat1.type() != CV_16UC1) && (mat1.type() != CV_16SC1) && (mat1.type() != CV_8UC1) && (mat1.type() != CV_8UC3) && (mat1.type() != CV_8SC1) && (mat1.type() != CV_16UC3) && (mat1.type() != CV_16SC3) && (mat1.type() != CV_64FC1) && (mat1.type() != CV_32FC1)) { 00409 printf("%s << ERROR! Equality check for this type (%d) has not been implemented!\n", __FUNCTION__, mat1.type()); 00410 return false; 00411 } 00412 00413 bool isStillValid = true; 00414 00415 #pragma omp parallel for 00416 for (int iii = 0; iii < mat1.rows; iii++) { 00417 for (int jjj = 0; jjj < mat1.cols; jjj++) { 00418 00419 if (!isStillValid) { 00420 break; 00421 } 00422 00423 switch (mat1.type()) { 00424 case CV_64FC1: 00425 //printf("%s << type: CV_64FC1\n", __FUNCTION__); 00426 if (mat1.at<double>(iii,jjj) != mat2.at<double>(iii,jjj)) { 00427 //printf("%s << (%d) (%d) \n", __FUNCTION__, mat1.at<double>(iii,jjj), mat2.at<double>(iii,jjj)); 00428 isStillValid = false; 00429 } 00430 break; 00431 case CV_32FC1: 00432 //printf("%s << type: CV_32FC1\n", __FUNCTION__); 00433 if (mat1.at<float>(iii,jjj) != mat2.at<float>(iii,jjj)) { 00434 //printf("%s << (%d) (%d) \n", __FUNCTION__, mat1.at<float>(iii,jjj), mat2.at<float>(iii,jjj)); 00435 isStillValid = false; 00436 } 00437 break; 00438 case CV_16UC1: 00439 //printf("%s << type: CV_16UC1\n", __FUNCTION__); 00440 if (mat1.at<unsigned short>(iii,jjj) != mat2.at<unsigned short>(iii,jjj)) { 00441 //printf("%s << (%d) (%d) \n", __FUNCTION__, mat1.at<unsigned short>(iii,jjj), mat2.at<unsigned short>(iii,jjj)); 00442 isStillValid = false; 00443 } 00444 break; 00445 case CV_16SC1: 00446 //printf("%s << type: CV_16SC1\n", __FUNCTION__); 00447 if (mat1.at<short>(iii,jjj) != mat2.at<short>(iii,jjj)) { 00448 isStillValid = false; 00449 } 00450 break; 00451 case CV_8UC1: 00452 //printf("%s << type: CV_8UC1\n", __FUNCTION__); 00453 if (mat1.at<unsigned char>(iii,jjj) != mat2.at<unsigned char>(iii,jjj)) { 00454 //printf("%s << (%d) (%d) \n", __FUNCTION__, mat1.at<unsigned char>(iii,jjj), mat2.at<unsigned char>(iii,jjj)); 00455 isStillValid = false; 00456 } 00457 break; 00458 case CV_8UC3: 00459 //printf("%s << type: CV_8UC3\n", __FUNCTION__); 00460 if ((mat1.at<Vec3b>(iii,jjj)[0] != mat2.at<Vec3b>(iii,jjj)[0]) || (mat1.at<Vec3b>(iii,jjj)[1] != mat2.at<Vec3b>(iii,jjj)[1]) || (mat1.at<Vec3b>(iii,jjj)[2] != mat2.at<Vec3b>(iii,jjj)[2])) { 00461 isStillValid = false; 00462 } 00463 break; 00464 case CV_8SC1: 00465 //printf("%s << type: CV_8SC1\n", __FUNCTION__); 00466 if (mat1.at<char>(iii,jjj) != mat2.at<char>(iii,jjj)) { 00467 isStillValid = false; 00468 } 00469 break; 00470 case CV_16UC3: 00471 //printf("%s << type: CV_16UC3\n", __FUNCTION__); 00472 if ((mat1.at<Vec3s>(iii,jjj)[0] != mat2.at<Vec3s>(iii,jjj)[0]) || (mat1.at<Vec3s>(iii,jjj)[1] != mat2.at<Vec3s>(iii,jjj)[1]) || (mat1.at<Vec3s>(iii,jjj)[2] != mat2.at<Vec3s>(iii,jjj)[2])) { 00473 isStillValid = false; 00474 } 00475 break; 00476 case CV_16SC3: 00477 //printf("%s << type: CV_16SC3\n", __FUNCTION__); 00478 if ((mat1.at<Vec3s>(iii,jjj)[0] != mat2.at<Vec3s>(iii,jjj)[0]) || (mat1.at<Vec3s>(iii,jjj)[1] != mat2.at<Vec3s>(iii,jjj)[1]) || (mat1.at<Vec3s>(iii,jjj)[2] != mat2.at<Vec3s>(iii,jjj)[2])) { 00479 isStillValid = false; 00480 } 00481 break; 00482 default: 00483 break; 00484 } 00485 } 00486 } 00487 00488 if (!isStillValid) { 00489 return false; 00490 } 00491 return true; 00492 00493 } 00494 00495 void randomSelection(vector<unsigned int>& src, vector<unsigned int>& dst, unsigned int max) { 00496 00497 dst.clear(); 00498 dst.insert(dst.end(), src.begin(), src.end()); 00499 00500 if (dst.size() <= max) { 00501 return; 00502 } 00503 00504 while (dst.size() > max) { 00505 dst.erase(dst.begin() + (rand() % dst.size())); 00506 } 00507 00508 } 00509 00510 double asymmetricGaussianValue(double score, double mean, double loVar, double hiVar) { 00511 00512 double zScore, sigma = 1.0, retVal; 00513 00514 if (score == mean) { 00515 return 1.00; 00516 } else if (score > mean+3*hiVar) { 00517 return 0.00; 00518 } else if (score < mean-3*loVar) { 00519 return 0.00; 00520 } else if (score > mean) { 00521 sigma = abs(hiVar - mean); 00522 } else if (score < mean) { 00523 sigma = abs(loVar - mean); 00524 } 00525 00526 zScore = (score - mean) / sigma; 00527 retVal = exp(-pow(zScore, 2.0)/2.0); 00528 00529 return retVal; 00530 00531 } 00532 00533 void addUniqueToVector(vector<unsigned int>& dst, vector<unsigned int>& src) { 00534 00535 for (unsigned int iii = 0; iii < src.size(); iii++) { 00536 00537 bool alreadyAdded = false; 00538 00539 for (unsigned int jjj = 0; jjj < dst.size(); jjj++) { 00540 if (dst.at(jjj) == src.at(iii)) { 00541 alreadyAdded = true; 00542 } 00543 00544 00545 } 00546 00547 if (!alreadyAdded) { 00548 dst.push_back(src.at(iii)); 00549 } 00550 00551 } 00552 00553 } 00554 00555 double calcLinePerpDistance(double *line1, double *line2) { 00556 double retVal = 0.0; 00557 00558 retVal = abs(line2[2] - line1[2]) / sqrt(pow(line1[0], 2) + pow(line1[1], 2)); 00559 00560 return retVal; 00561 } 00562 00563 Scalar getRandomColour() { 00564 Scalar color( rand()&255, rand()&255, rand()&255 ); 00565 00566 return color; 00567 } 00568 00569 long long int factorial(int num) 00570 { 00571 00572 long long int result=1; 00573 for (int i=1; i<=num; ++i) { 00574 //result=result*=i; 00575 result *= 1; 00576 } 00577 return result; 00578 00579 } 00580 00581 void getNextCombo(vector<unsigned int>& currentIndices, int r, int n) { 00582 00583 //bool maxed = false; 00584 bool valid = true; 00585 00586 //printf("%s << Entered function.\n", __FUNCTION__); 00587 00588 // If no indices tested, use default (0, 1, 2 etc) 00589 if (currentIndices.size() == 0) 00590 { 00591 for (int i = 0; i < r; i++) 00592 { 00593 currentIndices.push_back(i); 00594 } 00595 } 00596 else 00597 { 00598 00599 // Going back each digit 00600 int i = 0; 00601 00602 while (valid && (i < r)) 00603 { 00604 //printf("%s << i = %d / %d\n", __FUNCTION__, i, r); 00605 // If current index is about to go over its maximum... 00606 if (currentIndices.at(currentIndices.size()-i-1) > (n-2-i)) 00607 { 00608 //printf("%s << digit #(%d) is valid; less than %d\n", __FUNCTION__, currentIndices.size()-i-1, n-2-i); 00609 i++; // check out next index 00610 } 00611 else // Otherwise, just increment it, fill in trailing digits and exit while loop 00612 { 00613 currentIndices.at(currentIndices.size()-i-1) = currentIndices.at(currentIndices.size()-i-1) + 1; 00614 for (int j = 0; j < i; j++) 00615 { 00616 currentIndices.at(currentIndices.size()-i+j) = currentIndices.at(currentIndices.size()-i+j-1) + 1; 00617 } 00618 valid = false; 00619 } 00620 } 00621 00622 00623 } 00624 } 00625 00626 double findEquivalentProbabilityScore(double* values, int quantity, double prob) 00627 { 00628 00629 //int i = 0; 00630 vector<double> listVector; 00631 double min = 1.00; 00632 int minIndex; 00633 00634 // Push values into vector 00635 for (int j = 0; j < quantity; j++) 00636 { 00637 listVector.push_back(values[j]); 00638 } 00639 00640 // Pop minimum values off vector until you've reached sufficient depth for the probability 00641 while (listVector.size() >= (unsigned int)(std::max(int(prob*quantity), 1))) 00642 { 00643 //printf("%s << listVector.size() = %d, prob*quantity = %d\n", __FUNCTION__, listVector.size(), int(prob*quantity)); 00644 //cin.get(); 00645 min = 9e99; 00646 00647 for (unsigned int j = 0; j < listVector.size(); j++) 00648 { 00649 if (listVector.at(j) < min) 00650 { 00651 min = listVector.at(j); 00652 minIndex = j; 00653 } 00654 } 00655 00656 listVector.erase(listVector.begin() + minIndex); 00657 00658 } 00659 00660 return min; 00661 00662 } 00663 00664 void convert_byte_to_binary_string(void* src, char* dst) { 00665 00666 uint8_t* num; 00667 00668 num = (uint8_t*) src; 00669 00670 unsigned int factor = 128; 00671 00672 for (unsigned int iii = 0; iii < 8; iii++) { 00673 if (*num > factor) { 00674 dst[iii] = '1'; 00675 } else { 00676 dst[iii] = '0'; 00677 } 00678 factor /= 2; 00679 } 00680 dst[8] = '\0'; 00681 }