/** * \brief Unserialize the layer. */ void Layer::UnserializeFrom(const SerializerElement & element) { SetName(element.GetStringAttribute("name", "", "Name")); SetVisibility(element.GetBoolAttribute("visibility", true, "Visibility")); //Compatibility with GD <= 3.3 if (element.HasChild("Camera")) { for (std::size_t i = 0; i < element.GetChildrenCount("Camera"); ++i) { const SerializerElement & cameraElement = element.GetChild("Camera", i); SetCameraCount(GetCameraCount()+1); Camera & camera = GetCamera(GetCameraCount()-1); camera.SetUseDefaultSize(cameraElement.GetBoolAttribute("DefaultSize", true)); camera.SetSize(cameraElement.GetDoubleAttribute("Width"), cameraElement.GetDoubleAttribute("Height")); camera.SetUseDefaultViewport(cameraElement.GetBoolAttribute("DefaultViewport", true)); camera.SetViewport(cameraElement.GetDoubleAttribute("ViewportLeft"), cameraElement.GetDoubleAttribute("ViewportTop"), cameraElement.GetDoubleAttribute("ViewportRight"), cameraElement.GetDoubleAttribute("ViewportBottom") ); // (sf::Rect used Right and Bottom instead of Width and Height before) } } //End of compatibility code else { SerializerElement & camerasElement = element.GetChild("cameras"); camerasElement.ConsiderAsArrayOf("camera"); for (std::size_t i = 0; i < camerasElement.GetChildrenCount(); ++i) { const SerializerElement & cameraElement = camerasElement.GetChild(i); SetCameraCount(GetCameraCount()+1); Camera & camera = GetCamera(GetCameraCount()-1); camera.SetUseDefaultSize(cameraElement.GetBoolAttribute("defaultSize", true)); camera.SetSize(cameraElement.GetDoubleAttribute("width"), cameraElement.GetDoubleAttribute("height")); camera.SetUseDefaultViewport(cameraElement.GetBoolAttribute("defaultViewport", true)); camera.SetViewport(cameraElement.GetDoubleAttribute("viewportLeft"), cameraElement.GetDoubleAttribute("viewportTop"), cameraElement.GetDoubleAttribute("viewportRight"), cameraElement.GetDoubleAttribute("viewportBottom")); // (sf::Rect used Right and Bottom instead of Width and Height before) } } effects.clear(); SerializerElement & effectsElement = element.GetChild("effects"); effectsElement.ConsiderAsArrayOf("effect"); for (std::size_t i = 0; i < effectsElement.GetChildrenCount(); ++i) { const SerializerElement & effectElement = effectsElement.GetChild(i); auto effect = std::shared_ptr<gd::Effect>(new Effect); effect->UnserializeFrom(effectElement); effects.push_back(effect); } }
bool CvCalibFilter::LoadCameraParams( const char* filename ) { int i, j; int d = 0; FILE* f = fopen( filename, "r" ); isCalibrated = false; if( !f ) return false; if( fscanf( f, "%d", &d ) != 1 || d <= 0 || d > 10 ) return false; SetCameraCount( d ); for( i = 0; i < cameraCount; i++ ) { for( j = 0; j < (int)(sizeof(cameraParams[i])/sizeof(float)); j++ ) { int values_read = fscanf( f, "%f", &((float*)(cameraParams + i))[j] ); CV_Assert(values_read == 1); } } /* Load stereo params */ /* load quad */ for( i = 0; i < 2; i++ ) { for( j = 0; j < 4; j++ ) { int values_read = fscanf(f, "%f ", &(stereo.quad[i][j].x) ); CV_Assert(values_read == 1); values_read = fscanf(f, "%f ", &(stereo.quad[i][j].y) ); CV_Assert(values_read == 1); } } /* Load coeffs */ for( i = 0; i < 2; i++ ) { for( j = 0; j < 9; j++ ) { int values_read = fscanf(f, "%lf ", &(stereo.coeffs[i][j/3][j%3]) ); CV_Assert(values_read == 1); } } fclose(f); stereo.warpSize = cvSize( cvRound(cameraParams[0].imgSize[0]), cvRound(cameraParams[0].imgSize[1])); isCalibrated = true; return true; }
CvCalibFilter::~CvCalibFilter() { SetCameraCount(0); cvFree(&etalonParams); cvFree(&etalonPoints); cvReleaseMat(&grayImg); cvReleaseMat(&tempImg); cvReleaseMat(&undistImg); cvReleaseMemStorage(&storage); }