bool fileHandler::readFile(){ FILE *fp; if ((fp = fopen(mPath.c_str(), "rb+")) == NULL) { fprintf(stderr, "Can't open:<%s>\n", mPath); return false; } bool res = false; switch (mType){ case img: res = readImg(fp); break; case hdr: readHdr(fp); res = true; break; default: std::cerr << "not supported file type!" << std::endl; break; } fclose(fp); return res; }
void MjpegPlayer::start(const QString &complete_url) { m_connStatus = Stream::Playing; m_finishedConnection = false; m_reply = m_manager->get(QNetworkRequest(QUrl(complete_url))); connect( m_reply, SIGNAL(readyRead()), this, SLOT(readImg()) ); connect( m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(readError(QNetworkReply::NetworkError)) ); connect( m_reply, SIGNAL(finished()), this, SLOT(finishedConnection()) ); }
void MjpegPlayer::stop() { m_connStatus = Stream::Stopped; m_finishedConnection = true; if (m_reply) { disconnect( m_reply, SIGNAL(readyRead()), this, SLOT(readImg()) ); disconnect( m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(readError(QNetworkReply::NetworkError)) ); disconnect( m_reply, SIGNAL(finished()), this, SLOT(finishedConnection()) ); } }
void srf_read(FILE * const ifP, bool const verbose, struct srf * const srfP) { uint8_t trialCsum; size_t padLen; unsigned char pad[256]; unsigned int i; if (!readHeader(ifP, &srfP->header)) pm_error("short srf header"); if (!checkHeader(&srfP->header)) pm_error("invalid srf header"); if (verbose) pm_message("reading srf ver %s with prod code %s and %u images", srfP->header.ver.val, srfP->header.prod.val, srfP->header.img_cnt); MALLOCARRAY(srfP->imgs, srfP->header.img_cnt); if (!srfP->imgs) pm_error("Could not allocate memory for %u images", srfP->header.img_cnt); for (i = 0; i < srfP->header.img_cnt; ++i) if (!readImg(ifP, verbose, i, &srfP->imgs[i])) pm_error("invalid srf image %u", i); padLen = fread(pad, 1, sizeof(pad), ifP); if (!feof(ifP)) { pm_errormsg("excess data at end of file"); return; } trialCsum = csum(srfP, 0); /* initial value */ for (i = 0; i < padLen; ++i) trialCsum += pad[i]; if (trialCsum != 0) pm_errormsg("checksum does not match"); }
int main (int argc, char** argv) { double f; double vd; double r; int iter; double h; // argiment parsing if (pcl::console::parse_argument (argc, argv, "-r", r) >= 0) { MIN_DISTANCE = r; cout << "adjust the registration threshold to " << r << endl; } if (pcl::console::parse_argument (argc, argv, "-giter", iter) >= 0) { GITER = iter; cout << "adjust global alignment iterations to " << iter <<" iterations"<< endl; } if (pcl::console::parse_argument (argc, argv, "-hessian", h) >= 0) { HESSIAN=h; cout << "adjust SIFT matching threshold to " << h << endl; } if (pcl::console::find_argument (argc, argv, "-h") >= 0 || argc == 1) { printUsage (argv[0]); return 0; } if (pcl::console::find_argument (argc, argv, "-g") >= 0) { GLOBAL_FLAG = 1; cout << "Global Reistration is ON" << endl; } if (pcl::console::find_argument (argc, argv, "-lcoff") >= 0) { LOOP_CLOSURE = 0; cout << "Loop CLosure Detection is OFF" << endl; } if (pcl::console::find_argument (argc, argv, "-m") >= 0) { MLS = 1; cout << "Moving least square smoothing is ON" << endl; } if (pcl::console::find_argument (argc, argv, "-dn") >= 0) { DENOISING= 1; cout << "De-noising (statistic) is ON" << endl; } if (pcl::console::parse_argument (argc, argv, "-vd", vd) >= 0) { DEPTH_AVG = 1; cout << "Down-sampling is ON" << endl; if (vd>0.00001) { DOWN_SAMPLE = vd; cout<<"Down sample threshold is changed to "<<DOWN_SAMPLE<<endl; } } vector<PointCloud, Eigen::aligned_allocator<PointCloud> > data; vector<PointCloud, Eigen::aligned_allocator<PointCloud> > key3data; vector<vector<KeyPoint> > key2data; vector<pcl::CorrespondencesPtr> correspondencesdata; Mat previousrgb; vector<KeyPoint> previouskey2d; // read the rgb-d data one by one ifstream index; string root_dir = argv[1]; index.open (string(root_dir + "/input.txt").c_str()); int i = 0; while (!index.eof ()) { string file; index >> file; if (file.empty ()) break; file = root_dir + "/" + file; Mat rgbimg; Mat depimg; Mat mask; // read data readImg (file, "_rgb.png", rgbimg); readImg (file, "_depth.png", depimg); readImg (file, "_mask.png", mask); if (rgbimg.empty () || depimg.empty () || mask.empty ()) { printf ( "Error: The RGB-D file does not exit. Please note that the right format should be: \n"); printf ( "X_rgb.png, X_depth.png, X_mask.png with the same size. ('X' is your input) \n"); return (0); } if (rgbimg.size () != depimg.size () || rgbimg.size () != mask.size ()) { printf ( "Error: The RGB-D files are not consistent. The rgb, depth and mask images should have the same size. \n"); return (0); } cout << "loading: " << file << endl; // check the image size and the offest coordinate int x1, y1; if (rgbimg.rows == 480 && rgbimg.cols == 640) { // if the image is full size (480*640), no offset coordinate x1 = 0; y1 = 0; } else { // if not, read the offset file ifstream loc; string location1 = file + "_loc.txt"; loc.open (location1.c_str ()); if (!loc.is_open ()) { if (TOP_LEFT1!=0 && TOP_LEFT2!=0) { x1=TOP_LEFT2; y1=TOP_LEFT1; } else { cout << "Error! There is no associated off-set location file." << endl; return 0; } } else { char comma; loc >> x1 >> comma >> y1; } loc.close(); } // perform erosion to remove the noises around the boundary erosion (mask, 4); vector<KeyPoint> key2d; PointCloud pointcloud; PointCloud keypoints; // read data and perform surf feature matching read (rgbimg, depimg, mask, pointcloud, keypoints, key2d, x1, y1, HESSIAN); filter (pointcloud, 0.001, pointcloud); data.push_back (pointcloud); key3data.push_back (keypoints); key2data.push_back (key2d); // find the pairwise correspondecnes based on surf feature if (i >= 1) { pcl::CorrespondencesPtr correspondences (new pcl::Correspondences ()); //may have bugs?? vector<DMatch> good_matches; match (rgbimg, previousrgb, key2d, previouskey2d, good_matches, correspondences); correspondencesdata.push_back (correspondences); correspondences.reset (new pcl::Correspondences); } previousrgb = rgbimg; previouskey2d = key2d; i++; } index.close(); printf ("Loaded %d datasets.\n", (int) data.size ()); PointCloudPtr final (new PointCloud); vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > matrix_buffer; // registration: initial+fine+global //initialize the PCL viewer p = new pcl::visualization::PCLVisualizer (argc, argv, "3D Moeling example"); p->setSize (480, 640); p->setPosition (480, 200); // registration int first = 0; int last = 0; if (!LOOP_CLOSURE) { last=(int) data.size ()-1; } // need to change back double threshold = MIN_DISTANCE; for (int z = 0; z < GITER; z++) { vector<PointCloud, Eigen::aligned_allocator<PointCloud> > out; PointCloudPtr output (new PointCloud); PointCloudPtr final_temp (new PointCloud); if (GLOBAL_FLAG) { vector<PointCloud, Eigen::aligned_allocator<PointCloud> > out_global; if (z == 0) pairwiseAlign (data, correspondencesdata, key3data, *output, out, matrix_buffer, 1, threshold); else { pairwiseAlign (data, correspondencesdata, key3data, *output, out, matrix_buffer, 0, threshold); } // global optimization cout << endl << "Global optimization begins ... at iteration " <<z+1<< endl; globalAlign (out, final_temp, matrix_buffer, out_global, first, last); data = out_global; } else { pairwiseAlign (data, correspondencesdata, key3data, *output, out, matrix_buffer, 1, threshold); final = output; break; } threshold = threshold * 0.9; final = final_temp;