Esempio n. 1
0
double CalibCameraWrapperEx(
    cv::Point3f const * pts3d, cv::Point2f const * pts2d, unsigned int ptCount,
    unsigned int imgWidth, unsigned int imgHeight, float * intrinsicMatInOut,
    float * rotationOut, float * translationOut )
{
    cv::Mat distCoeffs_est;
    std::vector<cv::Mat> rvecs(1), tvecs(1);

    cv::Mat1d camMat_est(3,3, 0.);
    if( intrinsicMatInOut )
    {
        cv::Mat1f(3,3,intrinsicMatInOut).convertTo( camMat_est, CV_64F );
    }

    std::vector<std::vector<cv::Point3f>> test3d_list( 1 );
    test3d_list.front().assign( pts3d, pts3d + ptCount );
    
    std::vector<std::vector<cv::Point2f>> test2d_list( 1 );
    test2d_list.front().assign( pts2d, pts2d + ptCount );

    cv::Size2f const imgSize(imgWidth,imgHeight);

    int const flags = 
        (intrinsicMatInOut ? CV_CALIB_USE_INTRINSIC_GUESS : 0) |
        CV_CALIB_ZERO_TANGENT_DIST |
        CV_CALIB_FIX_K2 | CV_CALIB_FIX_K3 | CV_CALIB_FIX_K4 | CV_CALIB_FIX_K5 | CV_CALIB_FIX_K6;

    double rep_err = cv::calibrateCamera(test3d_list, test2d_list, imgSize,
        camMat_est, distCoeffs_est, rvecs, tvecs, flags );

    if( translationOut )
    {
        cv::Mat1f tempOut(1,3,translationOut);
        tvecs.front().convertTo( tempOut, CV_32F );
    }

    if( rotationOut )
    {
        cv::Mat1d temp(3,3);
        Rodrigues( rvecs.front(), temp );

        cv::Mat1f tempOut(3,3,rotationOut);
        temp.convertTo( tempOut, CV_32F );
    }

    if( intrinsicMatInOut )
    {
        cv::Mat1f tempOut(3,3,intrinsicMatInOut);
        camMat_est.convertTo( tempOut, CV_32F );
    }

    return rep_err;
}
Esempio n. 2
0
	void Framework::ConnectToServer()
	{
		xml_document doc;
		xml_node root = doc.append_child("join");
		root.append_attribute("password").set_value(m_brain->getPassword().c_str());
		root.append_attribute("name").set_value(m_brain->getName().c_str());

		try {
			std::ifstream avatarIn("MyAvatar.png", std::ios_base::in | std::ios_base::binary);
			if (!avatarIn.is_open())
				cerr << "Could not open avatar file!";
			else {
				base64::encoder E;
				stringstream  avatarOut;
				E.encode(avatarIn, avatarOut);

				avatarOut.seekg(0, ios::end);
				int avatarEncSize = avatarOut.tellg();
				avatarOut.seekg(0, ios::beg);

				char* avatarEnc = new char[avatarEncSize+1];
				avatarOut.read(avatarEnc, avatarEncSize);
				avatarEnc[avatarEncSize] = 0;

				std::ofstream tempOut("avatarEnc.txt", std::ios_base::out | std::ios_base::binary);
				tempOut.write(avatarEnc, avatarEncSize);
			
				xml_node ndAvatar = root.append_child("avatar");
				xml_node ndAvatarData = ndAvatar.append_child(pugi::node_pcdata);
				ndAvatarData.set_value(avatarEnc);

				delete [] avatarEnc;
			}
		}
		catch (...) {
			cerr << "Error loading avatar.";
		}

		stringstream out;
		doc.print(out);
		m_tcpClient->sendMessage(out.str());

		std::ofstream tempOut("connect.xml", std::ios_base::out | std::ios_base::binary);
		tempOut << out.str();
	}
void streamContentHandler::generate(utility::outputStream& os, const vmime::encoding& enc,
	const string::size_type maxLineLength) const
{
	if (!m_stream)
		return;

	// Managed data is already encoded
	if (isEncoded())
	{
		// The data is already encoded but the encoding specified for
		// the generation is different from the current one. We need
		// to re-encode data: decode from input buffer to temporary
		// buffer, and then re-encode to output stream...
		if (m_encoding != enc)
		{
			ref <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
			ref <utility::encoder::encoder> theEncoder = enc.getEncoder();

			theEncoder->getProperties()["maxlinelength"] = maxLineLength;
			theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

			m_stream->reset();  // may not work...

			std::ostringstream oss;
			utility::outputStreamAdapter tempOut(oss);

			theDecoder->decode(*m_stream, tempOut);

			string str = oss.str();
			utility::inputStreamStringAdapter tempIn(str);

			theEncoder->encode(tempIn, os);
		}
		// No encoding to perform
		else
		{
			m_stream->reset();  // may not work...

			utility::bufferedStreamCopy(*m_stream, os);
		}
	}
	// Need to encode data before
	else
	{
		ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
		theEncoder->getProperties()["maxlinelength"] = maxLineLength;
		theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

		m_stream->reset();  // may not work...

		theEncoder->encode(*m_stream, os);
	}
}
Esempio n. 4
0
void stringContentHandler::generate(utility::outputStream& os,
	const vmime::encoding& enc, const size_t maxLineLength) const
{
	// Managed data is already encoded
	if (isEncoded())
	{
		// The data is already encoded but the encoding specified for
		// the generation is different from the current one. We need
		// to re-encode data: decode from input buffer to temporary
		// buffer, and then re-encode to output stream...
		if (m_encoding != enc)
		{
			shared_ptr <utility::encoder::encoder> theDecoder = m_encoding.getEncoder();
			shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();

			theEncoder->getProperties()["maxlinelength"] = maxLineLength;
			theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

			utility::inputStreamStringProxyAdapter in(m_string);

			std::ostringstream oss;
			utility::outputStreamAdapter tempOut(oss);

			theDecoder->decode(in, tempOut);

			string str = oss.str();
			utility::inputStreamStringAdapter tempIn(str);

			theEncoder->encode(tempIn, os);
		}
		// No encoding to perform
		else
		{
			m_string.extract(os);
		}
	}
	// Need to encode data before
	else
	{
		shared_ptr <utility::encoder::encoder> theEncoder = enc.getEncoder();
		theEncoder->getProperties()["maxlinelength"] = maxLineLength;
		theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);

		utility::inputStreamStringProxyAdapter in(m_string);

		theEncoder->encode(in, os);
	}
}
Esempio n. 5
0
void DataManager::Export(DRef& dref, QDataStream& out)
{
    Data* pData = dref.m_pData;

    if (pData != NULL)
    {
        out << (qint32)BOI_STD_D_VERSION;
        out << (qint32)pData->Type();
        out << GetUuid(pData->Type());

        /*
         * Do not write the Data object directly to the
         * stream. This will allow implementations to
         * correctly skip over any unknown types. For
         * example, given the following stream:
         *
         *      out << QString << DRef << QString;
         * 
         * If the DRef data object was directly written
         * to the stream and then imported on a different
         * version of the system which does not support the
         * particular DRef type, the import would not be able
         * to read in the data and advance the stream to the
         * correct position to read the final QString.
         * Using a QByteArray avoids this situation because
         * the Import routine will always just read in a byte
         * array and thus advance the stream to the next
         * appropriate position (regardless of whether or not
         * the system supports the data type).
         */

        QByteArray byteArray;
        QBuffer buffer(&byteArray);
        buffer.open(QIODevice::WriteOnly);

        QDataStream tempOut(&buffer);
        pData->Export(tempOut);

        buffer.close();

        out << byteArray;
    }
    else
    {
        out << (qint32)BOI_STD_D_VERSION;
        out << (qint32)BOI_STD_D(Invalid);
    }
}
Esempio n. 6
0
int getLum(const Frame& in, Array2D8u& out, double quantile)
{
    assert(quantile >= 0.0);
    assert(quantile <= 1.0);

    Array2D8u tempOut(in.getWidth(), in.getHeight());

    const Channel* R;
    const Channel* G;
    const Channel* B;

    in.getXYZChannels(R, G, B);
    // convert to grayscale...
    utils::transform(R->begin(), R->end(), G->begin(), B->begin(),
                     tempOut.begin(), colorspace::ConvertRGB2Y());

    // build histogram
    vector<long> hist(256, 0);
    assert(hist.size() == 256u);

    for (Array2D8u::iterator it = tempOut.begin(); it != tempOut.end(); ++it)
    {
        ++hist[ *it ];
    }

    // find the quantile...
    size_t relativeQuantile = in.size()*quantile;
    size_t idx = 0;
    size_t cdf = 0;
    for (; idx < hist.size(); ++idx) {
        cdf += hist[idx];

        if ( cdf >= relativeQuantile ) break;
    }

    // return values...
    out.swap( tempOut );
    return idx;
}
Esempio n. 7
0
virtual void THallEffect::filterTo(TSignal & s)
{
	TSignal * in;
   
    unsigned int NumberOfPoints;

    // если это комбинированный сигнал.
    if( s[0]<-1.0 && s.back() >1.0)
    {
        feat(); // его надо усреднить
    // фильтровать будем усредненный сигнал
    }
    // если это обычный сигнал - фильтруем как есть.

    in=signal;  
    NumberOfPoints=in.size();

    // В эти массивы будут достраиваться данные для отрицательных магнитных полей.
    // Это очень мило, а если это сигнал для отрицательного магнитного поля?
    // То теоретически достраивается положительная часть.
    // Надо пофиксить тут комменты на адекватные действительности.
    TSignal tempIn(2*NumberOfPoints);
    TSignal tempOut(2*NumberOfPoints);

    // формируем сигнал для фильтра.
    // достраивая его в отрицательные магнитные поля.
    for (unsigned int i = 0; i < NumberOfPoints; i++)
    {
	    /*
	    Давайте внимательно сюда посмотрим.
	    У эффекта Холла отрицательная симметрия, относительно точки
	    B==0;
	    С чего вообще я взял, что это нулевой элемент? /(О_о)\

	    Получается для сигнала с положительным магнитным полем - это выполняется.
	    Для сигнала комбинированного, т.е. уже объединенного - это выполняется,
	    потому что фильтруется усредненный сигнал (по сути имеющий только значения
	    положительного магнитного поля.

	    Для отрицательного магнитного поля сие равенство, насколько мне ясно - не выполняется.
	    */        
        tempIn[i]=-(*inB)[NumberOfPoints-i-1];        
        tempIn[i+NumberOfPoints]=(*in)[i];
    } 

    /*
    В случае отрицательного магнитного поля надо инвертировать порядок элементов
    Потому что впереди выстраиваются значения для положительного магнитного поля.
    */

    if(tempIn[0]>1.0)
    {
        std::reverse(tempIn.begin(),tempIn.end());
    }
    // фильтруем 
    TrForMassiveFilter(tempIn,tempOut,filterParams.filterLength,filterParams.SamplingFrequecy,
                filterParams.BandwidthFrequency,filterParams.AttenuationFrequency);    
    // Размер внутри фильтра меняется, в зависимости от длины фильтра.
    NumberOfPoints=tempOut.size();
    s.clear();
    for(unsigned int i=fP.filterLength;i<NumberOfPoints;i++)
    {      
        s.push_back(tempOut[i]);
    }
}