示例#1
0
void LoadVideoThread::loadFromImages()
{
    qDebug() << "Start loading frames...";

    QDir dirImages(filePath);
    QFileInfoList listImages = dirImages.entryInfoList(QStringList() << "*.tif" << "*.tiff" << "*.jpg" << "*.png");

    if (0 == listImages.count())
    {
        emit completeLoading(false);
    }
    else
    {
        QFileInfoList::const_iterator it = listImages.begin();
        while(it != listImages.end())
        {
            cv::Mat frame = cv::imread(it->filePath().toStdString());
            cv::Mat rgbFrame;
            cv::cvtColor(frame, rgbFrame, CV_BGR2RGB);

            gtv->appendFrame(rgbFrame);
            it++;
        }
        emit completeLoading(true);
    }
    exit(0);
}
void StelQGLTextureBackend::loadFromPVR()
{
	invariant();
	//NOTE: We ignore bind options (mipmapping and filtering type) from params
	//      at the moment.
	//
	//      We also ignore maximum texture size (QGLContext::bindTexture should 
	//      fail if the texture is too large.
	//
	//      QGLContext::bindTexture handles gl texture format for us.
	QGLContext* context = prepareContextForLoading();
	glTextureID = context->bindTexture(path);
	if(glTextureID == 0)
	{
		errorOccured("loadFromPVR() failed to load a PVR file to a GL texture - "
		             "Maybe the file \"" + path + "\" is missing?");
		invariant();
		return;
	}
	// For some reason only LINEAR seems to work.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	setTextureWrapping();

	// This is an assumption; PVRTC can be either 4 or 2 bits per pixel - we assume the worse case.
	pixelBytes = 0.5f;

	completeLoading();
	invariant();
}
//Image struct is copied (data is not - implicit sharing), so that
//ensureTextureSizeWithinLimits won't affect the original image.
void StelQGLTextureBackend::loadFromImage(QImage image)
{
	invariant();

	if(image.isNull())
	{
		errorOccured("loadFromImage(): Image data to load from is null. "
		             "Maybe the image failed to load from file?");
		invariant();
		return;
	}

	// Shrink if needed.
	glEnsureTextureSizeWithinLimits(image);

	if(!renderer->areNonPowerOfTwoTexturesSupported() && 
		(!StelUtils::isPowerOfTwo(image.width()) ||
		 !StelUtils::isPowerOfTwo(image.height())))
	{
		errorOccured("loadFromImage(): Failed to load because the image has "
		             "non-power-of-two width and/or height while the renderer "
		             "backend only supports power-of-two dimensions");
		invariant();
		return;
	}

	GLint internalFormat = glGetTextureInternalFormat(image);
	switch(internalFormat)
	{
		case GL_RGBA8:             pixelBytes = 4.0f; break;
		case GL_RGB8:              pixelBytes = 3.0f; break;
		case GL_LUMINANCE8_ALPHA8: pixelBytes = 2.0f; break;
		case GL_LUMINANCE8:        pixelBytes = 1.0f; break;
		default: Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown GL internal format for QImage");
	}

	QGLContext* context = prepareContextForLoading();
	glTextureID = context->bindTexture(image, GL_TEXTURE_2D, internalFormat,
	                                   getTextureBindOptions(textureParams));
	if(glTextureID == 0)
	{
		errorOccured("loadFromImage(): Failed to load an image to a GL texture");
		invariant();
		return;
	}
	setTextureWrapping();

	completeLoading();                       
	invariant();
}
示例#4
0
void LoadVideoThread::loadFromVideo()
{
    qDebug() << "Start loading video...";

    cv::VideoCapture cap;
    if(!cap.open(filePath.toStdString()))
    {
        emit completeLoading(false);
    }
    else
    {
        gtv->setFrameCount((int)cap.get(CV_CAP_PROP_FRAME_COUNT));
        uint frameno = 0;
        for(;;)
        {
            cv::Mat frame;
            cap >> frame;
            if (!frame.data)
            {
                break;
            }
            frameno++;
            cv::Mat rgbFrame;
            cv::cvtColor(frame, rgbFrame, CV_BGR2RGB);

            // append it to data model
            gtv->appendFrame(rgbFrame);
        }
        cv::Mat truth((int)cap.get(CV_CAP_PROP_FRAME_HEIGHT),
                      (int)cap.get(CV_CAP_PROP_FRAME_WIDTH),
                      CV_8UC1, cv::Scalar(0));
        gtv->initializeGroundtruth(frameno, truth);
        emit completeLoading(true);
    }
    exit(0);
}
bool ofxImageSequence::loadSequence(string _folder)
{
	unloadSequence();

	folderToLoad = _folder;

	if(useThread){
		threadLoader = new ofxImageSequenceLoader(this);
		return true;
	}

	if(preloadAllFilenames()){
		completeLoading();
		return true;
	}
	
	return false;

}
示例#6
0
KisImageBuilder_Result KraConverter::buildImage(QIODevice *io)
{
    m_store = KoStore::createStore(io, KoStore::Read, "", KoStore::Zip);

    if (m_store->bad()) {
        m_doc->setErrorMessage(i18n("Not a valid Krita file"));
        return KisImageBuilder_RESULT_FAILURE;
    }

    bool success;
    {
        if (m_store->hasFile("root") || m_store->hasFile("maindoc.xml")) {   // Fallback to "old" file format (maindoc.xml)
            KoXmlDocument doc = KoXmlDocument(true);

            bool ok = oldLoadAndParse(m_store, "root", doc);
            if (ok)
                ok = loadXML(doc, m_store);
            if (!ok) {
                return KisImageBuilder_RESULT_FAILURE;
            }

        } else {
            errUI << "ERROR: No maindoc.xml" << endl;
            m_doc->setErrorMessage(i18n("Invalid document: no file 'maindoc.xml'."));
            return KisImageBuilder_RESULT_FAILURE;
        }

        if (m_store->hasFile("documentinfo.xml")) {
            KoXmlDocument doc = KoXmlDocument(true);
            if (oldLoadAndParse(m_store, "documentinfo.xml", doc)) {
                m_doc->documentInfo()->load(doc);
            }
        }
        success = completeLoading(m_store);
    }

    return success ? KisImageBuilder_RESULT_OK : KisImageBuilder_RESULT_FAILURE;
}