Пример #1
0
void colorBasics::process(cv::Mat &inMat, cv::Mat &outMat)
{
    if( method.compare("invert") == 0 )
    {
        invert( inMat, outMat );
    }

    if( method.compare("equalize") == 0 )
    {
        equalize( inMat, outMat );
    }

    if( method.compare("2rgb") == 0 )
    {
        convertToRGB( inMat, outMat );
    }

    if( method.compare("2hsv") == 0 )
    {
        convertToHSV( inMat, outMat );
    }

    if( method.compare("2gray") == 0 )
    {
        convertToGRAY( inMat, outMat );
    }
}
Пример #2
0
    // don't worry, we are modifying the color, so copying is appropriate
    inline Color apply_rgb_controls(Color color) const
    {
        if (m_gamma != 1.0f)
        {
            color_r(color) = powf(color_r(color), 1.0f / m_gamma);
            color_g(color) = powf(color_g(color), 1.0f / m_gamma);
            color_b(color) = powf(color_b(color), 1.0f / m_gamma);
        }

        if (m_hue_shift != 0.0f || m_saturation != 1.0f)
        {
            color = convertFromRGB(color);

            color_r(color) += m_hue_shift;
            color_r(color) = color_r(color) - floorf(color_r(color)); // keep hue in [0, 1]

            color_g(color) *= m_saturation;
            color = convertToRGB(color);
        }

        if (m_contrast != 1.0f)
            color = (color - make_color(m_contrast_pivot, m_contrast_pivot, m_contrast_pivot)) * m_contrast + make_color(m_contrast_pivot, m_contrast_pivot, m_contrast_pivot);

        if (m_exposure > 0.0001f)
            color *= powf(2.0f, m_exposure);

        if (m_multiply != 1.0f)
            color *= m_multiply;

        if (m_add != 0.0f)
            color = make_color(m_add, m_add, m_add);

        return color;
    }
Пример #3
0
void CWindow::DisplayFile()
{
    if(OpenedFile!="")
    {
        if(!OpenedFile.isNull())
        {
            this->setWindowTitle(OpenedFile);
            //read
            fstream file(OpenedFile.toStdString().c_str(),ios::in | ios::binary);

            benHeaderFile bhf;
            benHeaderInfo bhi;

            //file.seekg(0,ios::cur);
            int width, height;
            file.read((char*)&width, sizeof(int));
            file.read((char*)&height, sizeof(int));
            qDebug() << width ;
            qDebug() << height ;

            label->resize(width,height);
            label->setGeometry(QRect(0,20,width,height));
            QPixmap pix = QPixmap(width, height);
            p = new QPainter(&pix);

            p->setViewport(0,0,width, height);
            //base coat
            p->fillRect(QRect(0,0,width, height), QColor(255,255,255,255));


            for(unsigned i = 0; i < height; i++)
            {
                for(unsigned j = 0; j < width; j++)
                {
                    string color;
                    file.read((char*)&color, sizeof(string));
                    qDebug() << color.c_str();
                    p->setPen(convertToRGB(color));
                    p->drawPoint(j, i);
                }
            }
            label->setPixmap(pix);

            delete p;
        }
    }
}
Пример #4
0
/**
 * Reads a frame from the webcam, converts it into the RGB colorspace
 * and stores it in the webcam structure
 */
static void webcam_read(struct webcam *w)
{
    struct v4l2_buffer buf;

    // Try getting an image from the device
    for(;;) {
        CLEAR(buf);
        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        buf.memory = V4L2_MEMORY_MMAP;

        // Dequeue a (filled) buffer from the video device
        if (-1 == _ioctl(w->fd, VIDIOC_DQBUF, &buf)) {
            switch(errno) {
                case EAGAIN:
                    continue;

                case EIO:
                default:
                    fprintf(stderr, "[v4l2] %d: Could not read from device %s\n", errno, w->name);
                    break;
            }
        }

        // Make sure we are not out of bounds
        assert(buf.index < w->nbuffers);

        // Lock frame mutex, and store RGB
        pthread_mutex_lock(&w->mtx_frame);
        convertToRGB(w->buffers[buf.index], &w->frame);
        pthread_mutex_unlock(&w->mtx_frame);
        break;
    }

    // Queue buffer back into the video device
    if (-1 == _ioctl(w->fd, VIDIOC_QBUF, &buf)) {
        fprintf(stderr, "[v4l2] Error while swapping buffers on %s\n", w->name);
        return;
    }
}
Пример #5
0
static int display_frame(X11DisplaySink* sink, X11DisplayFrame* frame, const FrameInfo* frameInfo)
{
    struct timeval timeNow;
    long requiredUsec;
    long durationSlept;
    YUV_frame inputFrame;
    YUV_frame outputFrame;
    unsigned char* inputBuffer;
    unsigned char* rgbInputBuffer;
    StreamFormat rgbInputFormat;
    int frameDurationMsec;
    int frameSlippage;

    frameDurationMsec = (int)(1000 * frameInfo->frameRate.den / (double)(frameInfo->frameRate.num));
    frameSlippage = frameDurationMsec * 1000 / 2; /* half a frame */


    if (frame->videoIsPresent)
    {
        if (frame->videoFormat == UYVY_10BIT_FORMAT)
        {
            DitherFrame(frame->convertBuffer, frame->inputBuffer, sink->inputWidth * 2, (sink->inputWidth + 5) / 6 * 16,
                sink->inputWidth, sink->inputHeight);
            inputBuffer = frame->convertBuffer;
            rgbInputFormat = UYVY_FORMAT;
        }
        else
        {
            inputBuffer = frame->inputBuffer;
            rgbInputFormat = frame->videoFormat;
        }
        
        /* scale image */
        if (sink->swScale != 1)
        {
            YUV_frame_from_buffer(&inputFrame, (void*)inputBuffer,
                sink->inputWidth, sink->inputHeight, sink->yuvFormat);

            YUV_frame_from_buffer(&outputFrame, (void*)frame->scaleBuffer,
                sink->width, sink->height, sink->yuvFormat);

            small_pic(&inputFrame,
                &outputFrame,
                0,
                0,
                sink->swScale,
                sink->swScale,
                1,
                1,
                1,
                frame->scaleWorkspace);

            rgbInputBuffer = frame->scaleBuffer;
        }
        else
        {
            rgbInputBuffer = inputBuffer;
        }

        /* add OSD to frame */
        if (sink->osd != NULL && sink->osdInitialised)
        {
            if (!osd_add_to_image(sink->osd, frameInfo, rgbInputBuffer, sink->width, sink->height))
            {
                ml_log_error("Failed to add OSD to frame\n");
                /* continue anyway */
            }
        }

        /* convert frame to RGB */
        convertToRGB(sink, rgbInputFormat, rgbInputBuffer, frame->rgbBuffer, sink->width, sink->height);


        /* wait until it is time to display this frame */
        gettimeofday(&timeNow, NULL);
        durationSlept = 0;
        if (frameInfo->rateControl)
        {
            durationSlept = sleep_diff(frameDurationMsec * 1000, &timeNow, &sink->lastFrameTime);
        }


        XLockDisplay(sink->x11Common.windowInfo.display);
        
        if (sink->useSharedMemory)
        {
            XShmPutImage(sink->x11Common.windowInfo.display, sink->x11Common.windowInfo.window, sink->x11Common.windowInfo.gc,
                frame->xImage,
                0, 0, 0, 0,
                sink->width, sink->height,
                False);
        }
        else
        {
            XPutImage(sink->x11Common.windowInfo.display, sink->x11Common.windowInfo.window, sink->x11Common.windowInfo.gc,
                frame->xImage,
                0, 0, 0, 0,
                sink->width, sink->height);
        }

        XSync(sink->x11Common.windowInfo.display, False);

        XUnlockDisplay(sink->x11Common.windowInfo.display);

        
        x11c_process_events(&sink->x11Common);


        /* report that a new frame has been displayed */
        msl_frame_displayed(sink->listener, frameInfo);


        /* set the time that this frame was displayed */
        if (frameInfo->rateControl)
        {
            if (durationSlept < - frameSlippage)
            {
                /* reset rate control when slipped by more than frameSlippage */
                sink->lastFrameTime = timeNow;
            }
            else
            {
                /* set what the frame's display time should have been */
                requiredUsec = sink->lastFrameTime.tv_sec * 1000000 + sink->lastFrameTime.tv_usec + frameDurationMsec * 1000;
                sink->lastFrameTime.tv_usec = requiredUsec % 1000000;
                sink->lastFrameTime.tv_sec = requiredUsec / 1000000;
            }
        }
        else
        {
            gettimeofday(&sink->lastFrameTime, NULL);
        }
    }
    else
    {
        gettimeofday(&sink->lastFrameTime, NULL);
    }


    reset_streams(frame);

    return 1;
}