示例#1
0
Album ParserAlbum::getAlbumFromFile(const QString &_name)
{
    m_pFile->close();
    if(!m_pFile->open(QIODevice::ReadOnly))
    {
        qDebug() << "Can`t open file : " << m_pFile->fileName();
    }
    Album newAlbum;
    newAlbum.setName(_name);
    QDomElement element = m_pDoc->documentElement();
    QDomNode node = element.firstChild();
    while(!node.isNull())
    {
        if(node.isElement())
        {
            QDomElement domElement = node.toElement();
            if(domElement.nodeName() == "images")
            {
                if(domElement.hasChildNodes())
                {
                    getImages(newAlbum,domElement.childNodes());
                }
            }
            if(domElement.nodeName() == "current")
            {
                newAlbum.setCurrentIndex(domElement.text().toInt());
            }
            node = node.nextSibling().toElement();
        }
    } 
    m_pFile->close();
    return newAlbum;
}
示例#2
0
void SankakuTest::testAnimatedUrls()
{
	QList<Image*> images = getImages("Sankaku", "idol.sankakucomplex.com", "regex", "animated rating:safe");

	// Convert results
	QStringList md5s, urls;
	for (Image *img : images)
	{
		md5s.append(img->md5());
		urls.append(img->url());
	}

	// Check results
	md5s = md5s.mid(0, 3);
	QStringList expected = QStringList() << "6e7901eea2a5a2d2b96244593ed190df" << "97b3355a7af0bfabc67f2678a4a837fd" << "d9f7f5089da4a677846d77da2c146088";
	QCOMPARE(images.count(), 20);
	QCOMPARE(md5s, expected);

	// Compare URLs
	QStringList expectedUrls = QStringList()
							   << "https://is.sankakucomplex.com/data/6e/79/6e7901eea2a5a2d2b96244593ed190df.gif"
							   << "https://is.sankakucomplex.com/data/97/b3/97b3355a7af0bfabc67f2678a4a837fd.gif"
							   << "https://is.sankakucomplex.com/data/d9/f7/d9f7f5089da4a677846d77da2c146088.webm";
	QStringList actualUrls = urls.mid(0, 3);
	QCOMPARE(actualUrls, expectedUrls);
}
示例#3
0
static int imageload (CSOUND *csound, IMGLOAD * p)
{
    char filename[255];

    Images *pimages;
    Image *img;

    pimages = getImages(csound);

    pimages->cnt++;
    pimages->images =
      (Image **) csound->ReAlloc(csound, pimages->images,
                                 sizeof(Image *) * pimages->cnt);

    strncpy(filename, (char*) (p->ifilnam->data), 254);

    img = __doOpenImage(filename, csound);

    if (LIKELY(img)) {
      pimages->images[pimages->cnt-1] = img;
      *(p->kn) = (MYFLT) pimages->cnt;
      return OK;
    }
    else {
      return csound->InitError(csound,
                               Str("imageload: cannot open image %s.\n"),
                               filename);
    }
}
示例#4
0
void Sprite::setTransparentColor(color_t color)
{
  m_transparentColor = color;

  // Change the mask color of all images.
  std::vector<Image*> images;
  getImages(images);
  for (Image* image : images)
    image->setMaskColor(color);
}
示例#5
0
int Sprite::getMemSize() const
{
  int size = 0;

  std::vector<Image*> images;
  getImages(images);
  for (Image* image : images)
    size += image->getRowStrideSize() * image->height();

  return size;
}
示例#6
0
void DerpibooruTest::testHtml()
{
	QList<Image*> images = getImages("Booru-on-rails", "derpibooru.org", "regex", "safe", "results.html");

	// Convert results
	QList<int> ids;
	for (Image *img : images)
	{
		ids.append(img->id());
	}

	// Check results
	ids = ids.mid(0, 3);
	QList<int> expected = QList<int>() << 1334191 << 1334187 << 1334186;
	QCOMPARE(images.count(), 15);
	QCOMPARE(ids, expected);
}
示例#7
0
void DerpibooruTest::testJson()
{
	QList<Image*> images = getImages("Booru-on-rails", "derpibooru.org", "json", "safe", "results.json");

	// Convert results
	QList<int> ids;
	for (Image *img : images)
	{
		ids.append(img->id());
	}

	// Check results
	ids = ids.mid(0, 3);
	QList<int> expected = QList<int>() << 1248664 << 1248663 << 1248661;
	QCOMPARE(images.count(), 15);
	QCOMPARE(ids, expected);
}
示例#8
0
void SankakuTest::testHtml()
{
	QList<Image*> images = getImages("Sankaku", "idol.sankakucomplex.com", "regex", "rating:safe");

	// Convert results
	QStringList md5s;
	for (Image *img : images)
	{
		md5s.append(img->md5());
	}

	// Check results
	md5s = md5s.mid(0, 3);
	QStringList expected = QStringList() << "7af162c8a2e5299d737de002fce087cf" << "8dd5c24458feb851c4dfbb302ebf5c06" << "33347fcbeb76b6d7d2c31a5d491d53ee";
	QCOMPARE(images.count(), 20);
	QCOMPARE(md5s, expected);
}
示例#9
0
bool SmugMug::deleteDuplicates(SmugID albumId)
{
	OwnedArray<ImageItem> images;
	if (getImages(images, albumId))
	{
		OwnedArray<SmugID> duplicateIds;
		StringArray fileNames;

		for (int i = 0; i < images.size(); i++)
		{
			if (fileNames.contains(images[i]->filename))
				duplicateIds.add(new SmugID(images[i]->id));
			else
				fileNames.add(images[i]->filename);
		}

		for (int i = 0; i < duplicateIds.size(); i++)
			deleteImage(*duplicateIds[i]);

		return true;
	}
	return false;
}
示例#10
0
/**
 * Loads a model from a file if needed or increases its refrence count.
 * @return Pointer to the loaded model.
 */
Model* ResourceManager::loadModel(const string filename) {
	map< string, pair<Model*, int> >::iterator moditer = models_.find(filename);
	Model* model = NULL;
	if(moditer != models_.end()) {
		pair<Model*, int> modref = moditer->second;
		model = modref.first;
		modref.second++;
	} else {
		//int fullpath_size = strlen(DIRECTORY_MODELS) + strlen(filename) +1;
		//char* fullpath = malloc(fullpath_size);
		//snprintf(fullpath, fullpath_size, "%s%s", DIRECTORY_MODELS, filename);
		DEBUG_A("FLAG1 '%s', '%s'", DIRECTORY_MOD.c_str(), filename.c_str());
		string fullpath = DIRECTORY_MOD + filename;
		DEBUG_A("FLAG2");
		model = RCBC_LoadFile(fullpath.c_str(), getImages());
		DEBUG_L("Loading model '%s'", fullpath.c_str());
		pair<Model*, int> modref(model, 1);
		models_.insert(pair<string, pair<Model*, int> >(filename, modref));
		//free(fullpath);
	}

	return model;
}
示例#11
0
static int imagecreate (CSOUND *csound, IMGCREATE * p)
{
    Images *pimages;
    Image *img;

    pimages = getImages(csound);

    pimages->cnt++;
    pimages->images =
      (Image **) csound->ReAlloc(csound, pimages->images,
                                 sizeof(Image *) * pimages->cnt);

    img = createImage(*p->kw, *p->kh);

    if (UNLIKELY(img==NULL)) {
      return csound->InitError(csound, Str("Cannot allocate memory.\n"));
    }
    else {
      pimages->images[pimages->cnt-1] = img;
      *(p->kn) = (MYFLT) pimages->cnt;
      return OK;
    }
}
示例#12
0
void ImageForeground::draw(DrawActionBase *, Viewport *vp)
{
    if(getActive() == false)
        return;

    UInt16 i;
    
    for(i = 0; i < getMFPositions()->size(); i++)
    {
        if(getImages(i) != NullFC)
            break;
    }
    
    if(i == getMFPositions()->size())   // all images == NULL?
        return; 

    glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT | 
                 GL_LIGHTING_BIT);

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glDisable(GL_DEPTH_TEST);

    glDisable(GL_COLOR_MATERIAL);

    glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, 1, 0, 1, 0, 1);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    float vpWidth = 1.0, vpHeight = 1.0;
    if(vp)
    {
        // for absolute pixel position
        vpWidth  = 1.0/vp->getPixelWidth();
        vpHeight = 1.0/vp->getPixelHeight();
    }

    for(i = 0; i < getMFPositions()->size(); i++)
    {
        ImagePtr img = getImages(i);

        if(img == NullFC)
            continue;

        Pnt2f p = getPositions(i);
        if( p[0] >= 1.0 || p[1] >= 1.0 )
            glRasterPos2f(p[0]*vpWidth, p[1]*vpHeight); // absolute position
        else
            glRasterPos2f(p[0], p[1]); // relative position

        glDrawPixels(img->getWidth(), img->getHeight(),
                     img->getPixelFormat(), GL_UNSIGNED_BYTE,
                     img->getData());
    }
    glDisable(GL_BLEND);
        

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glPopAttrib();
}
示例#13
0
void ARController::ProcessFrame(Engine * engine)
{
    if (!isInitialized)
        return;

    frameCount++;
    //Calc FPS
    struct timespec currentTime;
    SET_TIME(&currentTime);
    double frameTimeMicrosec = calc_time_double(lastFrameTime,currentTime);
    lastFrameTime = currentTime;
    float frameFps = (float)(1000000.0/frameTimeMicrosec);
    fpsAverage = (fpsAverage+frameFps)/2.0f;
    char fpsString[10];
    sprintf(fpsString,"%3.1f",fpsAverage);
    fpsLabel->SetText(fpsString);

    int debugLevel = debugUI->GetIntegerParameter("ARControllerDebug");
    bool useGuess = debugUI->GetBooleanParameter("UseGuess");
    bool showEntireBinary = debugUI->GetBooleanParameter("Show Entire Binary");


    //This section is the default per-frame operations
    FrameItem * item = frameList->next();
    item->clearOldData();
    //engine->getTime(&item->time);

    LOGV(LOGTAG_ARCONTROLLER,"Processing frame #%d, FPS=%f.",frameCount,fpsAverage);
    //Loose objects: QR=%d, Rect=%d, Circ=%d, FP=%d",
    //frameCount,fpsAverage,(int)QRCode::instanceCount,DebugRectangle::instanceCount,DebugCircle::instanceCount, FinderPattern::instanceCount);

    //If paused, keep reusing image until unpaused
    if (!paused)
    {
        getImages(engine);
    }
    else
    {
        //Need to refresh the RGB image
        cvtColor(*grayImage, *rgbImage, CV_GRAY2RGBA, 4);
    }

    vector<Drawable*> debugVector;

    item->qrCode = qrFinder->LocateQRCodes(*grayImage, debugVector, ( frameList->size() > 1) ? frameList->getRelative(-1)->qrCode : NULL);

    //What happens past here depends on the state
    if (controllerState == ControllerStates::Loading)
    {
        //Update world loader
        worldLoader->Update(engine);

        WorldStates::WorldState worldState = worldLoader->GetState();

        if (worldState == WorldStates::LookingForCode)
        {
            debugUI->SetLabelValue("State","Searching");

            if (item->qrCode != NULL && item->qrCode->isValidCode())
            {
                struct timespec decodeStart,decodeEnd;
                SET_TIME(&decodeStart);
                qrDecoder->DecodeQRCode(grayImage,binaryImage,item->qrCode,debugVector);
                SET_TIME(&decodeEnd);
                LOG_TIME("Decode",decodeStart,decodeEnd);
                if (item->qrCode->isDecoded())
                {
                    string codeText = "Code=";
                    codeText.append(item->qrCode->TextValue);
                    debugUI->SetLabelValue("CurrentCode",codeText);
                    currentCode = item->qrCode->TextValue;

                    if (debugUI->GetBooleanParameter("CodeOnly"))
                    {
                        LOGI(LOGTAG_ARCONTROLLER,"Code found (%s), still searching since we're in debug mode",currentCode.c_str());
                    }
                    else if (engine->communicator->IsConnected())
                    {
                        worldLoader->LoadRealm(item->qrCode->TextValue);
                    }
                    else //If not connected, just add a test object
                    {
                        LOGI(LOGTAG_ARCONTROLLER,"Starting in offline mode.");

                        debugUI->SetLabelValue("State","OfflineMode");
                        initializeARView(engine);

                        ARObject * myCube1 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(0,0,0));

                        //ARObject * myCube2 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(50,10,0));
                        //augmentedView->AddObject(myCube2);
                        //myCube2->BoundingSphereRadius = 30;
                        //ARObject * myCube3 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(-50,-10,0));
                        //augmentedView->AddObject(myCube3);
                        //myCube3->BoundingSphereRadius = 30;

                        augmentedView->AddObject(myCube1);
                        myCube1->BoundingSphereRadius = 12;

                        SetState(ControllerStates::Running);
                        delete worldLoader;
                        worldLoader = NULL;
                    }
                }
                else
                    LOGD(LOGTAG_ARCONTROLLER,"QRCode not decoded");
            }
        }
        else if (worldState == WorldStates::WaitingForRealm || worldState == WorldStates::WaitingForResources)
        {
            if (worldState == WorldStates::WaitingForRealm)
                debugUI->SetLabelValue("State","WaitRealm");
            else
                debugUI->SetLabelValue("State","WaitRsrc");

        }
        //The world is ready and loaded, so do normal AR processing
        else if (worldState == WorldStates::WorldReady)
        {
            debugUI->SetLabelValue("State","LoadCompl");
            initializeARView(engine);
            LOGD(LOGTAG_ARCONTROLLER,"Populating ARView using loaded world");
            worldLoader->PopulateARView(augmentedView);
            SetState(ControllerStates::Running);
            currentQRSize = debugUI->GetParameter("QRSize"); //Should be using value from server
            delete worldLoader;
            worldLoader = NULL;
        }
        else
        {
            char stateString[100];
            sprintf(stateString,"WrldState=%d",(int)worldState);
            debugUI->SetLabelValue("State",stateString);
            LOGW(LOGTAG_ARCONTROLLER,"Unexpected state");
        }
    }
    else if (controllerState == ControllerStates::Running)
    {
        debugUI->SetLabelValue("State","Run");

        bool doSkip = false;
        if (item->qrCode != NULL && item->qrCode->isValidCode())
        {

            if (recheckNext)
            {
                LOGD(LOGTAG_ARCONTROLLER,"Rechecking code. Current value = %s",currentCode.c_str());
                qrDecoder->DecodeQRCode(grayImage,binaryImage,item->qrCode,debugVector);

                if (item->qrCode->isDecoded() && item->qrCode->TextValue != currentCode)
                {
                    if (worldLoader == NULL)
                        worldLoader = new WorldLoader();
                    else
                    {
                        delete worldLoader;
                        worldLoader = new WorldLoader();
                    }
                    LOGD(LOGTAG_ARCONTROLLER,"Changing to code %s",currentCode.c_str());
                    currentCode = item->qrCode->TextValue;
                    worldLoader->LoadRealm(currentCode);
                    SetState(ControllerStates::Loading);
                    delete augmentedView;
                    augmentedView = NULL;
                    recheckNext = false;
                    doSkip = true;
                }
                else if (item->qrCode->isDecoded())
                    recheckNext = false;
            }
            else
            {
                if (useGuess)
                    positionSelector->GetPreviousResult(item);

                LOGV(LOGTAG_QR,"Getting position");
                currentQRSize = debugUI->GetParameter("QRSize"); //Should be using value from server
                item->qrCode->QRCodeDimension = currentQRSize;
                qrLocator->transformPoints(item->qrCode,*(item->rotationMatrix),*(item->translationMatrix),useGuess);
                debugUI->SetTranslation(item->translationMatrix);
                debugUI->SetRotation(item->rotationMatrix);
            }
        }

        certaintyIndicator->EnableOutline(recheckNext);
        if (!doSkip)
        {
            //Evaluate the position
            float resultCertainty = positionSelector->UpdatePosition(engine,item);
            certaintyIndicator->SetCertainty(resultCertainty);

            if (resultCertainty > 0 && augmentedView != NULL)
            {
                augmentedView->SetFOV(debugUI->GetParameter("FOV"));
                augmentedView->SetTransformations(item->translationMatrix,item->rotationMatrix,item->gyroRotation);
            }
            if (augmentedView != NULL)
                augmentedView->Update(rgbImage,engine);
        }
    }
    else
    {
        char stateString[100];
        sprintf(stateString,"ContState=%d",(int)controllerState);
        debugUI->SetLabelValue("State",stateString);
        LOGW(LOGTAG_ARCONTROLLER,"Unexpected state: %s",stateString);
    }

    if (debugUI->currentDrawMode == DrawModes::BinaryImage)
    {
        if (showEntireBinary)
        {
            ImageProcessor::SimpleThreshold(grayImage,binaryImage);
            cvtColor(*binaryImage, *rgbImage, CV_GRAY2RGBA, 4);
        }
        else
        {
            LOGD(LOGTAG_ARCONTROLLER,"Binary debug draw");
            cvtColor(*binaryImage, *rgbImage, CV_GRAY2RGBA, 4);
            LOGD(LOGTAG_ARCONTROLLER,"Binary debug draw complete");
        }
    }

    if (drawingLevel == 1 || drawingLevel == 3)
    {
        if (item->qrCode != NULL)
        {
            item->qrCode->SetDrawingLevel(debugLevel);
            item->qrCode->Draw(rgbImage);
        }

        struct timespec draw_start, draw_end;
        SET_TIME(&draw_start);
        while (!debugVector.empty())
        {
            debugVector.back()->Draw(rgbImage);
            delete debugVector.back();
            debugVector.pop_back();
        }
        SET_TIME(&draw_end);
        LOG_TIME_PRECISE("DebugDrawing",draw_start,draw_end);
    }
    else //Still need to clean up debug vector!!!!
    {
        struct timespec draw_start, draw_end;
        SET_TIME(&draw_start);
        while (!debugVector.empty())
        {
            delete debugVector.back();
            debugVector.pop_back();
        }
        SET_TIME(&draw_end);
        LOG_TIME_PRECISE("DebugCleanup",draw_start,draw_end);
    }


    //Do final processing
    Draw(rgbImage);
}
示例#14
0
std::vector<piece> puzzle::extract_pieces(std::string path, bool needs_filter){
    std::vector<piece> pieces;
    imlist color_images = getImages(path);
    
    //Threshold the image, anything of intensity greater than 45 becomes white (255)
    //anything below becomes 0
//    imlist blured_images = blur(color_images, 7, 5);

    imlist bw;
    if(needs_filter){
        imlist blured_images = median_blur(color_images, 5);
        bw = color_to_bw(blured_images,threshold);
    } else{
        bw= color_to_bw(color_images, threshold);
        filter(bw,2);
    }

//    cv::imwrite("/tmp/final/thresh.png", bw[0]);

    
    //For each input image
    for(int i = 0; i<color_images.size(); i++){
        std::vector<std::vector<cv::Point> > contours;
        
        //This isn't used but the opencv function wants it anyways.
        std::vector<cv::Vec4i> hierarchy;
        
        //Need to clone b/c it will get modified
        cv::findContours(bw[i].clone(), contours, hierarchy, cv::RETR_LIST, cv::CHAIN_APPROX_NONE);

        
        //For each contour in that image
        //TODO: (In anticipation of the other TODO's Re-create the b/w image
        //    based off of the contour to eliminate noise in the layer mask
        for(int j = 0; j<contours.size(); j++){
            int bordersize = 15;
            cv::Rect r =  cv::boundingRect(contours[j]);
            if(r.width < piece_size || r.height < piece_size) continue;

            
            
            cv::Mat new_bw = cv::Mat::zeros(r.height+2*bordersize,r.width+2*bordersize,CV_8UC1);
            std::vector<std::vector<cv::Point> > contours_to_draw;
            contours_to_draw.push_back(translate_contour(contours[j], bordersize-r.x, bordersize-r.y));
            cv::drawContours(new_bw, contours_to_draw, -1, cv::Scalar(255), CV_FILLED);
            //        std::cout << out_file_name.str() << std::endl;
            //        cv::imwrite(out_file_name.str(), m);
//            cv::imwrite("/tmp/final/new_bw.png", new_bw);

            r.width += bordersize*2;
            r.height += bordersize*2;
            r.x -= bordersize;
            r.y -= bordersize;
//            cv::imwrite("/tmp/final/bw.png", bw[i](r));            
            cv::Mat mini_color = color_images[i](r);
            cv::Mat mini_bw = new_bw;//bw[i](r);
            //Create a copy so it can't conflict.
            mini_color = mini_color.clone();
            mini_bw = mini_bw.clone();
            
            piece p(mini_color, mini_bw, piece_size);
            pieces.push_back(p);
            
        }
    }
    
    return pieces;
}