Вопрос

I have a window displaying a grid of thumbnail images. When I click an image it will either be selected or deselected. If it is deselected then the image is greyed out, if it is selected then the original image is displayed.

To do this requires the window to be redrawn with either the original or greyed out images. The issue I am having is instead of getting a cleared window, whenever I click I simply overlay the existing content with the new content.

Below is where I draw my thumbnails and display them in the window, this function is called every time an Image is clicked and I want to re draw the window contents.

void dispThumbs()
{
    Mat disp = Mat(500,620,CV_8UC3);
    imshow("Tile",disp);
    int ind = 0;
    int xdist = 5;
    int ydist = 5;
    for(int i = 0; i < 3; i++)
    {
        for(int k = 0; k < 3; k++)
        {
            Mat im = imMan.returnThumb(ind);
            im.copyTo(disp(Rect(xdist,ydist,200,150)));
            ind ++;
            ydist += 155;
        }
        ydist = 5;
        xdist += 205;
    }
    imshow("Tile",disp);
}

Is there a way to clear the contents of the window "Tile" and then redraw with the updated contents?

EDIT:

I am still having the same issue after adding this at the start of the dispThumbs() function.

 Mat disp = Mat::zeros(500,620,CV_8UC3);

When I click one of the thumbnails the relevant image is either set to selected or deselected then dispThumbs() is called again. Currently whenever I click, the already dimmed images just get darker. I cannot see any issue in the code i use for this but perhaps you can find a reason why the images keep getting darker.

Mat im = imMan.returnThumb(ind);

Calls the following two functions. If a thumbnail is not selected then I dim the image and return it.

Mat imManage::dimImage(Mat tmp)
{
    cout << "Dimming Image" << endl;
    int rows = tmp.rows;
    int cols = tmp.cols;

    for (int i = 0; i < rows; i++)
    {
        for(int k = 0; k < cols; k++)
        {
            tmp.at<cv::Vec3b>(i,k)[0] = saturate_cast<uchar>((int) tmp.at<cv::Vec3b>(i,k)[0] - 150);
            tmp.at<cv::Vec3b>(i,k)[1] = saturate_cast<uchar>((int) tmp.at<cv::Vec3b>(i,k)[1] - 150);
            tmp.at<cv::Vec3b>(i,k)[2] = saturate_cast<uchar>((int) tmp.at<cv::Vec3b>(i,k)[2] - 150);
        }
    }
    return tmp;
}

Mat imManage::returnThumb(int ind)
{
    imClass temp = images[ind];
    Mat th;
    if(temp.isSelected())
    {
        cout << ind << " Selected" << endl;
        th = temp.getThumb();
    } else {
        cout << ind << " De Selected" << endl;
        th = dimImage(temp.getThumb());
    }

   return th;
}
Это было полезно?

Решение

You can simply reset the Mat disp's content before filling new data:

disp = zeros(disp.rows, disp.cols);

or

disp.setTo(Scalar(0,0,0));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top