Ask Your Question

Tduck's profile - activity

2020-04-14 01:47:31 -0600 received badge  Popular Question (source)
2014-07-27 10:01:17 -0600 asked a question Imread a string location

I'm trying to load images from locations written in a file. It reads the string fileLocation correctly, and if I write the actual location (for example: imread("images/tif/image-001.tif", 1)) it also works. However, combining them seems to give me an empty image message. Please help.

// Read the file location from the file called locations.txt and save it to a string called fileLocation
string fileLocation;
ifstream infile;
infile.open ("locations.txt");
getline(infile, fileLocation);
infile.close();

// Read image with location fileLocation
imageColor = imread(fileLocation, 1);

// Check to see if the image has read properly
if (imageColor.empty())
{
    cout << "Image is empty\n";
    return -1;
}
2014-02-16 11:33:16 -0600 received badge  Editor (source)
2014-02-16 11:31:45 -0600 asked a question destroyWindow closes all windows and stops c++ program

I'm writing an live video processing program in c++, and want to be able to toggle three windows with the same mjpeg stream, in color, grayscale, and monochrome. I have all the image feeds running, but, since my screen is small, I want to be able to toggle them on and off individually. To do this, I have written the code below, but calling destroyWindow("[windowname]"); stops the whole program, instead. I've already read the documentation, and putting void in front of it doesn't help. Can anybody tell me what I'm doing wrong? I already tried asking on stackoverflow. There wasn't much help there. Here's the code (it's in an infinite loop, until the break you see below is called):

imshow("Color", imageColor);
imshow("Monochrome", imageMonochrome);
imshow("Grayscale", imageGrayscale);

int keyPressed = waitKey(0);
if (keyPressed > 0)
{
    cout << keyPressed;
    cout << "key was pressed\n";
    // Press C to toggle color window
    if (99 == keyPressed)
    {
        if (colorOpen)
        {
            cout << "Color window closed\n";
            destroyWindow("Color");
            colorOpen = false;
        }
        if (!colorOpen)
        {   
            cout << "Color window opened\n";
            imshow("Color", imageColor);
            colorOpen = true;
        }
    }

    // Press M to toggle monochrome window
    if (109 == keyPressed)
    {
        if (monochromeOpen)
        {
            cout << "Monochrome window closed\n";
            destroyWindow("Monochrome");
            monochromeOpen = false;
        }
        if (!monochromeOpen)
        {
            cout << "Monochrome window opened\n";
            imshow("Monochrome", imagebw);
            monochromeOpen = true;
        }
    }

    // Press G to toggle grayscale window
    if (103 == keyPressed)
    {
        if (grayscaleOpen)
        {
            cout << "Grayscale window closed\n";
            destroyWindow("Grayscale");
            grayscaleOpen = false;
        }
        if (!grayscaleOpen)
        {
            cout << "Grayscale window opened\n";
            imshow("Grayscale", image);
            grayscaleOpen = true;
        }
    }
    // Break out of infinite loop when [ESC] is pressed:   
    if (27 == keyPressed)
    {
        cout << "Escape Pressed\n";
        break;
    }
}