Ask Your Question
1

OpenCV VideoCapture 2fps

asked 2020-04-01 20:42:23 -0500

Nnnb19 gravatar image

Hey guys, so im trying to use aruco detect_markers. It works normally, but the image is only 640x480 (which is bad for a 720p camera) I tried to raise it to 720p with (cv::CAP_PROP_FRAME_WIDTH,1280); and height, but it lowers the fps down to about 2fps. I have no clue whats wrong

cv::VideoCapture inputVideo;

int waitTime;
if(!video.empty()) {
    inputVideo.open(video);
    waitTime = 0;
} else {
    inputVideo.open(camId);
    waitTime = 1;
}

double totalTime = 0;
int totalIterations = 0;

while(inputVideo.grab()) {
    inputVideo.set(cv::CAP_PROP_FRAME_WIDTH,1280);
    inputVideo.set(cv::CAP_PROP_FRAME_HEIGHT,720);

    cv::Mat image, imageCopy;
    inputVideo.retrieve(image);
    image.copyTo(imageCopy);

    double tick = (double)getTickCount();

    vector< int > ids;
    vector< vector< Point2f > > corners, rejected;
    vector< Vec3d > rvecs, tvecs;

    // detect markers and estimate pose
    aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
    if(estimatePose && ids.size() > 0)
        aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs,
                                         tvecs);

    double currentTime = ((double)getTickCount() - tick) / getTickFrequency();
    totalTime += currentTime;
    totalIterations++;
    if(totalIterations % 30 == 0) {
        cout << "Detection Time = " << currentTime * 1000 << " ms "
             << "(Mean = " << 1000 * totalTime / double(totalIterations) << " ms)" << endl;
    }

    // draw results


    if(ids.size() > 0) {
        aruco::drawDetectedMarkers(imageCopy, corners, ids);

        if(estimatePose) {
            for(unsigned int i = 0; i < ids.size(); i++)
                aruco::drawAxis(imageCopy, camMatrix, distCoeffs, rvecs[i], tvecs[i],
                                markerLength * 0.5f);
        }
    }

    if(showRejected && rejected.size() > 0)
        aruco::drawDetectedMarkers(imageCopy, rejected, noArray(), Scalar(100, 0, 255));

    imshow("out", imageCopy);
    char key = (char)cv::waitKey(waitTime);
    if (key == 27)
        break;
}

inputVideo.release();
return 0;

}

edit retag flag offensive close merge delete

Comments

Is your webam is 640s450 or 1080p?

supra56 gravatar imagesupra56 ( 2020-04-03 21:14:18 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-02 12:56:43 -0500

crackwitz gravatar image

remove everything that isn't capture. see if the problem is actually capture, or all the other stuff you need to calculate for every frame.

then check if another program (VLC? ffmpeg? gstreamer?) can display camera video at your requested parameters.

try different "backends". opencv supports ffmpeg, gstreamer, v4l2, ... some of those have ways to affect the color space and encoding of the picture or even request MJPEG or H.264.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-04-01 20:42:23 -0500

Seen: 124 times

Last updated: Apr 02