void CreateLookupTable( const calibu::CameraInterface<double>& cam_from, LookupTable& lut ) { /* TODO figure out what K should be for the "new" camera based on what part of the original image we want to keep. // Work out parameters of "new" linear camera. We want to map range // width/height to image via K. const calibu::Range range_width = calibu::MinMaxRotatedCol( cam_from, Eigen::Matrix3d::Identity() ); const calibu::Range range_height = calibu::MinMaxRotatedRow( cam_from, Eigen::Matrix3d::Identity() ); printf(" range_width.Size() = %f, range_width.maxr = %f, range_width.minr = %f\n", range_width.Size(), range_width.maxr, range_width.minr ); printf(" range_height.Size() = %f, range_height.maxr = %f, range_height.minr = %f\n", range_height.Size(), range_height.maxr, range_height.minr ); double fu = (cam_from.Width()-1) / range_width.Size(); double fv = (cam_from.Height()-1) / range_height.Size(); double u0 = -fu * range_width.minr; double v0 = -fv * range_height.minr; */ // This is a hack as there is no guarntee the first 4 params are the K // matrix. Really we should workout what a good linear model would be // based on what portion of the original image is on the z=1 plane (e.g., // cameras with FOV > 180 will need to ignore some pixels). double fu = cam_from.GetParams()[0]; double fv = cam_from.GetParams()[1]; double u0 = cam_from.GetParams()[2]; double v0 = cam_from.GetParams()[3]; // linear camera model inv(K) matrix Eigen::Matrix3d R_onKinv; R_onKinv << 1.0/fu, 0, -u0 / fu, 0, 1.0/fv, -v0 / fv, 0, 0, 1; CreateLookupTable( cam_from, R_onKinv, lut ); }
void ImageBrowser5D::Setup() { if(!img) return; for(int c=0; c<img->GetImageInfo()->numChannels; ++c) m_chflag.push_back(true); CreateObjects(); CreateLayout(); CreateLookupTable(); CreateVolumeProperties(); CreateInteractorStyle(); UpdateVSlider(); UpdateHSlider(); UpdateRenderer(); this->resize(img->GetImageInfo()->numColumns, img->GetImageInfo()->numRows); this->setAttribute ( Qt::WA_DeleteOnClose ); this->setWindowTitle(tr("Image Browser")); }
void * Radiometric::convert(unsigned short *kounts, int size, void *buf) { if(Units == Counts && (WordType == Short || WordType == Ushort) && UserM == 1.0 && UserC == 0.0 && UserG == 1.0 ) memcpy(buf,kounts,size*WordSize[WordType]); else{ if (!Table) CreateLookupTable(); switch(WordType){ case Char:{ register char * table = ( char *) Table; register char * convertedData = (char *) buf; for(int i=0; i < size; i++) *convertedData++ = *(table+(*kounts++)); } break; case Uchar:{ register unsigned char * table = ( unsigned char * ) Table; register unsigned char * convertedData = (unsigned char * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Short:{ register short * table = ( short * ) Table; register short * convertedData = ( short * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Ushort:{ register unsigned short * table = ( unsigned short * ) Table; register unsigned short * convertedData = ( unsigned short * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Int:{ register int * table = ( int * ) Table; register int * convertedData = (int * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Uint:{ register unsigned int * table = ( unsigned int * ) Table; register unsigned int * convertedData = (unsigned int * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Float:{ register float * table = ( float *) Table; register float * convertedData = (float * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; case Double:{ register double * table = (double *) Table; register double * convertedData = (double * ) buf; for ( int i = 0; i < size; i++ ) *convertedData++ = *(table+(*kounts++)); } break; default: break; } } return (buf); }
calibu::CameraModelT<Pinhole> CreateScanlineRectifiedLookupAndCameras( const Sophus::SE3d T_rl, const calibu::CameraModelInterface& cam_left, const calibu::CameraModelInterface& cam_right, Sophus::SE3d& T_nr_nl, LookupTable& left_lut, LookupTable& right_lut ) { const Sophus::SO3d R_rl = T_rl.so3(); const Sophus::SO3d R_lr = R_rl.inverse(); const Eigen::Vector3d l_r = T_rl.translation(); const Eigen::Vector3d r_l = - (R_lr * l_r); // Current up vector for each camera (in left FoR) const Eigen::Vector3d lup_l = Eigen::Vector3d(0,-1,0); const Eigen::Vector3d rup_l = R_lr * Eigen::Vector3d(0,-1,0); // Hypothetical fwd vector for each camera, perpendicular to baseline (in left FoR) const Eigen::Vector3d lfwd_l = (lup_l.cross(r_l)).normalized(); const Eigen::Vector3d rfwd_l = (rup_l.cross(r_l)).normalized(); // New fwd is average of left / right hypothetical baselines (also perpendicular to baseline) const Eigen::Vector3d avgfwd_l = lfwd_l + rfwd_l; // Define new basis (in left FoR); const Eigen::Vector3d x_l = r_l.normalized(); const Eigen::Vector3d z_l = avgfwd_l.normalized(); const Eigen::Vector3d y_l = z_l.cross(x_l).normalized(); // New orientation for both left and right cameras (expressed relative to original left) Eigen::Matrix3d Rnl_l; Rnl_l << x_l, y_l, z_l; // By definition, the right camera now lies exactly on the x-axis with the same orientation // as the left camera. T_nr_nl = Sophus::SE3d(Eigen::Matrix3d::Identity(), Eigen::Vector3d(-r_l.norm(),0,0) ); // Work out parameters of new linear camera const Range range_width = //Intersection( MinMaxRotatedCol(cam_left, Rnl_l); // MinMaxRotatedCol(cam_right, Rnl_l) // ); const Range range_height = //Intersection( MinMaxRotatedRow(cam_left, Rnl_l); // MinMaxRotatedRow(cam_right, Rnl_l) // ); // We want to map range width/height to image via K. const double fu = (cam_left.Width()-1) / range_width.Size(); const double fv = (cam_left.Height()-1) / range_height.Size(); const double u0 = -fu * range_width.minr; const double v0 = -fv * range_height.minr; // Setup new camera calibu::CameraModelT<Pinhole> new_cam(cam_left.Width(),cam_left.Height()); new_cam.Params() << fu, fv, u0, v0; // Homographies which should be applied to left and right images to scan-line rectify them const Eigen::Matrix3d Rl_nlKlinv = Rnl_l.transpose() * new_cam.Kinv(); const Eigen::Matrix3d Rr_nrKlinv = R_lr.inverse().matrix() * Rnl_l.transpose() * new_cam.Kinv(); CreateLookupTable(cam_left, Rl_nlKlinv, left_lut ); CreateLookupTable(cam_right, Rr_nrKlinv, right_lut ); return new_cam; }