void silhouetteCount(string nameImageFile){

    int silhouetteCounter=0;
    GImage* imageFile = new GImage(nameImageFile);
    GBufferedImage* imgageInBuffer = new GBufferedImage(0,0,imageFile->getWidth(), imageFile->getHeight());
    imgageInBuffer->load(nameImageFile);

    int imgHaight = imgageInBuffer->getHeight();
    int imgWidth = imgageInBuffer->getWidth();

    GWindow gw(imgWidth, imgHaight);
    gw.add(imageFile);

    myGrid imageBinaring(imgHaight, imgWidth);

    binaringImageToGrid(imgageInBuffer, imageBinaring);
    bool silhouetteIsValid = false;
    for(int x = 0; x < imgHaight; x++){
        for (int y = 0; y < imgWidth; y++){
            if (imageBinaring.get_color(x,y) == true && imageBinaring.get_visited(x,y) == false) {
                selectFindeArea(x,y, imageBinaring, silhouetteIsValid);
                if (silhouetteIsValid) silhouetteCounter++;
            }
        }
    }
    cout<<"in File: "<<nameImageFile<<"; found "<< silhouetteCounter<<" silhouettes."<<endl;
    cout<<endl;

    delete imgageInBuffer;
    delete imageFile;

}
コード例 #2
0
/* This function takes a picture and make from it filled grid. Each element of
 * grid is image`s pixel. Grid is filled with boolean values. If it is a black
 * point, it will be marked as true, other - false.
 */
void imageParsing(string fileName) {
    string fileAdress = "images/";
    fileAdress = fileAdress + fileName;
    GBufferedImage image;
    image.load(fileAdress);
    pixels.resize(image.getWidth(), image.getHeight());
    for (int column = 0; column < image.getWidth(); column++) {
        for (int row = 0; row < image.getHeight(); row++) {
            if (image.getRGB(column, row) <= GREY) {
                pixels.set(column, row, true);
            } else {
                pixels.set(column, row, false);
            }
        }
    }
    for (int column = 0; column < pixels.nCols; column++) {
        for (int row = 0; row < pixels.nRows; row++) {
            if (pixels.inBounds(column, row) && pixels.get(column, row) == true) {
                pixels.set(column, row, false);
                Points blackPoint = makePoint(column, row);
                checkAllNeighbours.push(blackPoint);
                detectingSilouettes(pixels);
            }
        }
    }
}
コード例 #3
0
ファイル: fauxtoshop.cpp プロジェクト: chuzui/courses
/* STARTER CODE HELPER FUNCTION - DO NOT EDIT
 *
 * Attempts to open the image file 'filename'.
 *
 * This function returns true when the image file was successfully
 * opened and the 'img' object now contains that image, otherwise it
 * returns false.
 */
static bool openImageFromFilename(GBufferedImage &img, string filename) {
    try { img.load(filename); }
    catch (...) { return false; }
    return true;
}