Ejemplo n.º 1
0
  void ColorCalibrate::canvasClicked(int x, int y, int brushSize, bool leftClick)
  {
    std::cout << "Clicked " << x << " " << y << " " << std::endl;

    messages::YUVImage image;
    if(currentCamera == Camera::TOP) image = topImageIn.message();
    else image = bottomImageIn.message();

    byte yi = image.yImage().getPixel(x, y);
    byte u = image.uImage().getPixel(x/2, y);
    byte v = image.vImage().getPixel(x/2, y);

    std::cout << "YUV " << (int)yi << " " << (int)u << " " <<
      (int)v << std::endl;

    image::Color color;
    color.setYuv(yi, u, v);
    std::cout << "HSZ " << color.getH() << " " << color.getS() <<
      " " << color.getZ() << std::endl;

    currentColorSpace->verboseContains(color);

    if (!leftClick) {
      std::cout << "Right click " << std::endl;
      bool changed = currentColorSpace->expandToFit(color);
      if (changed) {
        colorSpaceWidget.setColorSpace(currentColorSpace);
      }
    }

    updateThresholdedImage();
    std::cout << std::endl;
  }
Ejemplo n.º 2
0
void ColorCalibrate::selectColorSpace(int index) {
    currentColorSpace = &colorSpace[index];
    colorWheel.setColorSpace(currentColorSpace);
    colorSpaceWidget.setColorSpace(currentColorSpace);
	if (!displayAllColors) {
		updateThresholdedImage();
	}
}
Ejemplo n.º 3
0
void ColorTableCreator::paintMeLikeOneOfYourFrenchGirls(const BrushStroke& brushStroke) {

    // Check the click was on the image
    for (int i = -brushStroke.brushSize/2; i <= brushStroke.brushSize/2; i++) {
        for (int j = -brushStroke.brushSize/2; j <= brushStroke.brushSize/2; j++) {

            int brush_x = i + brushStroke.x;
            int brush_y = j + brushStroke.y;

            BMPYUVImage* image;

            if (currentCamera == Camera::TOP) {
                image = topImage;
            } else {
                image = bottomImage;
            }

            // Get the color from the image and emit it
            if(0 < brush_x && brush_x < image->getWidth() &&  0 < brush_y && brush_y < image->getHeight()) {

                byte y = image->getYUVImage()->getY(brush_x, brush_y);
                byte u = image->getYUVImage()->getU(brush_x, brush_y);
                byte v = image->getYUVImage()->getV(brush_x, brush_y);

                //TODO: hack? there must be a better way to do this - Octavian

                // these values reflect the downscaled Y, U, V values from the image acquisition

                int scaled_brush_x = brush_x/2;
                int scaled_brush_y = brush_y/2;

                // y image stores the sum of 4 neighboring pixels, so average it
                int y1 = sensors->getYImage(Camera::BOTTOM)[scaled_brush_y*AVERAGED_IMAGE_WIDTH + scaled_brush_x]/2;
                // u,v image stores the sum of 2 neighboring pixels so average it
                // also since they're stored together we need to compute special offsets for each
                int u1 = sensors->getUVImage(Camera::BOTTOM)[scaled_brush_y*AVERAGED_IMAGE_WIDTH*2 + scaled_brush_x*2];
                int v1 = sensors->getUVImage(Camera::BOTTOM)[scaled_brush_y*AVERAGED_IMAGE_WIDTH*2 + scaled_brush_x*2 + 1];

                std::cout << (int) y << " " << (int) u << " " << (int) v << std::endl;
                std::cout << (int) y1 << " " << (int) u1 << " " << (int) v1 << std::endl;

                if (brushStroke.define) {
                    colorTable.setColor(y, u, v, image::Color_bits[brushStroke.color]);
                    colorTable.setColor(y1, u1, v1, image::Color_bits[brushStroke.color]);
                } else {
                    colorTable.unSetColor(y, u, v, image::Color_bits[brushStroke.color]);
                    colorTable.unSetColor(y1, u1, v1, image::Color_bits[brushStroke.color]);
                }
            }
        }
    }

    updateThresholdedImage();
}
Ejemplo n.º 4
0
// This gets called every time the logs are advanced, ie every time the
// "forward" button is pressed in the main tool
void ColorTableCreator::run_()
{
    bottomImageIn.latch();
    topImageIn.latch();

    bottomImage.setMessage(portals::Message<messages::YUVImage>(
                               &bottomImageIn.message()));
    topImage.setMessage(portals::Message<messages::YUVImage>(
                            &topImageIn.message()));

    updateThresholdedImage();
}
Ejemplo n.º 5
0
void ColorTableCreator::loadColorTable(){
    QString base_directory = QString(NBITES_DIR) + "/data/tables";
    QString filename = QFileDialog::getOpenFileName(this,
                    tr("Load Color Table from File"),
                    base_directory,
                    tr("Color Table files (*.mtb)"));
    colorTable.read(filename.toStdString());
    colorTableName->setText(filename);

    serializeTableName(filename);
    updateThresholdedImage();
}
Ejemplo n.º 6
0
void ColorCalibrate::run_()
{
    topImageIn.latch();
    bottomImageIn.latch();

    topImage.setMessage(portals::Message<messages::YUVImage>(
                            &topImageIn.message()));
    bottomImage.setMessage(portals::Message<messages::YUVImage>(
                               &bottomImageIn.message()));

      subdiagram.run();
    updateThresholdedImage();
}
Ejemplo n.º 7
0
void ColorTableCreator::imageTabSwitched(int)
{
    // Rewire the thresholded display's inPortal to get the right thing
    if (imageTabs->currentWidget() == &topDisplay) {
        currentCamera = Camera::TOP;
        thrDisplay.imageIn.wireTo(&topConverter.thrImage);
    } else {
        currentCamera = Camera::BOTTOM;
        thrDisplay.imageIn.wireTo(&bottomConverter.thrImage);
    }

    loadLatestTable();
    updateThresholdedImage();
}
Ejemplo n.º 8
0
void ColorTableCreator::paintStroke(const BrushStroke& brushStroke)
{
    // Check the click was on the image
    for (int i = -brushStroke.brushSize/2; i <= brushStroke.brushSize/2; i++)
    {
        for (int j = -brushStroke.brushSize/2; j <= brushStroke.brushSize/2; j++)
        {
            int brush_x = i + brushStroke.x;
            int brush_y = j + brushStroke.y;

            messages::YUVImage image;

            if (currentCamera == Camera::TOP)
            {
                image = topImageIn.message();
            }
            else
            {
                image = bottomImageIn.message();
            }

            // Get the color from the image and emit it
            if(0 < brush_x && brush_x < image.width()/2 &&
               0 < brush_y && brush_y < image.height())
            {
                byte y = image.yImage().getPixel(brush_x, brush_y);
                byte u = image.uImage().getPixel(brush_x/2, brush_y);
                byte v = image.vImage().getPixel(brush_x/2, brush_y);

                //std::cout << (int) y << " " << (int) u << " " << (int) v
                //       << std::endl;

                if (brushStroke.define)
                {
                    colorTable.setColor(y, u, v,
                                        image::Color_bits[brushStroke.color]);
                }
                else
                {
                    colorTable.unSetColor(y, u, v,
                                          image::Color_bits[brushStroke.color]);
                }
            }
        }
    }
   updateThresholdedImage();
}