Ask Your Question
0

Wrong position of image

asked 2014-05-30 03:50:19 -0600

Koon gravatar image

OpenCV get wrong position of image from the source. When I open video from other program, look OK. But OpenCV moves image to right too much (get black stripe on the left).

How to fix this problem?

edit retag flag offensive close merge delete

Comments

3

src-code, version info, demo img ?

have a look at the faq as well, please.

berak gravatar imageberak ( 2014-05-30 03:56:00 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-06-02 07:13:58 -0600

hi...A Samsung DLP TV projects a high-quality picture; unfortunately, after about two years, the picture starts to fade and eventually dies out completely. The TV will also start to shut off with no warning after a few minutes. [

http://www.rubbergymmats.co.uk

](http://www.rubbergymmats.co.uk )

edit flag offensive delete link more
0

answered 2014-06-02 04:07:19 -0600

Koon gravatar image
  1. I has this problem since version 2.2 until now version 2.4
  2. I attached pictures from my customer to compare C:\fakepath\Tendo - Old Program - Windows Library.jpg C:\fakepath\Tendo - New Program - OpenCV 2.4.jpg

And this is sourcecode : -

IplImage *image = 0;

// const int MAX_COUNT = 500; // char* status = 0; int night_mode = 0; // int flags = 0;

CvCapture* capture = 0; CvVideoWriter * writer = 0;

sprintf(_window_name, "CAMERA : %d", _request_cam_id+1); cvNamedWindow( _window_name, 0 );

// Set Always on Top int x = CAPTURE_WINDOW_OFFSET; int y = CAPTURE_WINDOW_OFFSET; setWindowAlwaysTop(_window_name, x, y, CAPTURE_WINDOW_WIDTH, CAPTURE_WINDOW_HEIGHT); disableCloseWindowButton(_window_name);

capture = cvCaptureFromCAM(CV_CAP_DSHOW + _request_cam_id ); _camera = _request_cam_id;

cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, CAPTURE_FPS); // 10 qDebug() << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH) << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);

double f = 1.0; double w = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH) * f; double h = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT) * f; if(f != 1.0) { // set camera properties 320x240 is the best resolution cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, w); //opencv doesnt like 640x480 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, h); //as most webcams use YUYV/YUY2 codecs. }

if( ! capture ) { const QString errText("Could not initialize capturing...\n"); qDebug() << errText; writeLog(errText); return; }

while( _request_cam_id >= 0 ) // for(;;) { if(_request_cam_id != _camera) { cvDestroyWindow(_window_name);

    if(_camera < 0) break;

    sprintf(_window_name, "CAMERA : %d", _request_cam_id+1);
    cvNamedWindow( _window_name, 0 );

    // Set Always on Top
    int x = CAPTURE_WINDOW_OFFSET;
    int y = CAPTURE_WINDOW_OFFSET;
    setWindowAlwaysTop(_window_name, x, y, CAPTURE_WINDOW_WIDTH, CAPTURE_WINDOW_HEIGHT);
    disableCloseWindowButton(_window_name);

    capture = cvCaptureFromCAM(CV_CAP_DSHOW + _request_cam_id );
    // set camera properties 320x240 is the best resolution
    if(f != 1)
    {
        cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH,  w); //opencv doesnt like 640x480
        cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, h); //as most webcams use YUYV/YUY2 codecs.
    }
    cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, CAPTURE_FPS);    //Playstation Eye Only: Max FPS goes to 120!!!

    _camera = _request_cam_id;

    if( ! capture )
    {
        const QString errText("Could capture from requested camera...\n");
        qDebug() << errText;
        writeLog(errText);
        break;
    }
}

IplImage* frame = 0;
int c;

frame = cvQueryFrame( capture );
if( ! frame )
    break;

if( ! image )
{
    // allocate all the buffers //
    // image = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 3 );
    qDebug() << "Depth : " << frame->depth << " Channels : " << frame->nChannels;
    image = cvCreateImage(cvSize(frame->width, frame->height), frame->depth, frame->nChannels);
    image->origin = frame->origin;
    // status = (char*)cvAlloc(MAX_COUNT);
    // flags = 0;
}

// Clipping
if( ! _camera_clip.isEmpty() )
{
    // Custom Clipping
    QStringList l = _camera_clip.split(",");
    if(l.count() == 4)
    {
        // x, y, right, bottom
        long right = l.at(2).toLong();
        long bottom = l.at(3).toLong();

        long w = l.at(2).toLong() - l.at(0).toLong();
        long h = l.at(3).toLong() - l.at(1).toLong();

        qDebug() << QString("Custom camera clip recangle (%1):-\n"
            "Left  : %2\n"
            "Top   : %3\n"
            "Right : %4\n"
            "Bottom: %5\n"
            "From %6x%7")
                                            .arg(_camera_clip).arg(l.at(0)).arg(l.at(1)).arg(right).arg(bottom)

.arg(frame->width).arg(frame->height);

        if( (right > frame->width) || (bottom > frame->height) )
        {
            this->error = QString("Invalid clipping value, should not over than %1x%2")
                        .arg(frame->width).arg(frame->height);

            ((CaptureForm *)captureForm)->showMessage("INVALID CLIPPING VALUE", this->error);

            break;

        } else {

            CvRect rect = cvRect(l.at(0).toLong(), l.at(1).toLong(), w, h);

            cvSetImageROI(frame, rect);

            image = cvCreateImage(cvSize(rect.width, rect.height), frame->depth, frame->nChannels);
        }
    }
}

cvCopy( frame, image, 0 );

/** Marking for Region Of Interest **/
if(_zoom < 1.0)
{
    CvRect rect = getZoomRect(image);
    cvRectangle(image ...
(more)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-30 03:50:19 -0600

Seen: 602 times

Last updated: Jun 02 '14