Ask Your Question
1

Wrong resolution (video capture)

asked 2012-12-14 18:58:27 -0500

dinamex gravatar image

updated 2012-12-17 08:07:59 -0500

Hi all,

I'm using CV2.3.1 on a ARM Board and I would like to implement a webcam into my ROS project with MJPEG compression. But when I try to select a supported resolution (verified with $ v4l2-ctl --list-formats-ext) of 1920x1080 CV changes the resolution to 1600x896. Is there a specific reason our could it be possible that CV doesnt support this HD Webcam (Logitech c920). How can I see which resolutions are supported?



Here is my code:

#include "panda_kinect/OpenCVTools.h"
#include "ros/ros.h"
#include "image_transport/image_transport.h"
#include "sensor_msgs/CompressedImage.h"

int main(int argc, char *argv[])
{
        // init ros
        ros::init(argc, argv, "WebcamServer");

        ros::NodeHandle nh;
        image_transport::ImageTransport it(nh);

        image_transport::Publisher pub = it.advertise("/panda_cam/image_raw", 1);
        //ros::Publisher pub = nh.advertise<sensor_msgs::CompressedImage>("/camera/rgb/image_color/compressed", 1);

        bool show_fps;
        double desired_fps;
        nh.param<bool>("/WebcamServer/show_fps", show_fps, false);
        nh.param<double>("/WebcamServer/fps", desired_fps, 30.0);
        double fps = 0.0;
        int fpsCount = 0;

        ros::Rate rate(desired_fps);

        cv::VideoCapture cap(CV_CAP_V4L);
        cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);
        //cap.set(CV_CAP_PROP_FOURCC, 'M', 'J', 'P', 'G');


        if (cap.isOpened() == false)
        {
                ROS_ERROR("Failed to open webcam.");
                return 0;
        }

        //int frameCount = 0;
        while (ros::ok())
        {
                rate.sleep();

                if (show_fps && cap.isOpened())
                {
                        double cycleTime = rate.cycleTime().toSec();
                        if (cycleTime != 0.0)
                        {
                                fps += (1.0 / cycleTime);
                                fpsCount++;

                                if (fpsCount == 10)
                                {
                                        ROS_INFO("Rate: %lf", std::min(desired_fps, fps / fpsCount));
                                        fps = 0.0;
                                        fpsCount = 0;
                                }
                        }
                }

                if (pub.getNumSubscribers())
                {
                        cv::Mat frame;
                        frame.cols = 1920;
                        frame.rows = 1080;
                        cap >> frame;
                        pub.publish(OpenCVTools::matToImage(frame));

                        sensor_msgs::CompressedImage rgb_c;
                        rgb_c.header.stamp = ros::Time::now();
                        std::vector<int> p;
                        p.push_back(CV_IMWRITE_JPEG_QUALITY);
                        p.push_back(95);
                        cv::imencode(".jpg", frame, rgb_c.data, p);

                        //pub.publish(rgb_c);

                        /*
                        char path[255];
                        sprintf(path,"/home/scrusr/ros/panda_kinect/bin/images/frame%.4d.jpg", frameCount);
                        frameCount++;
                        cv::imwrite(path, frame);
                        */
                }

                ros::spinOnce();
        }
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-12-31 09:43:30 -0500

professorguy gravatar image

I can say that I'm using the Logitech C920 with OpenCV and I'm getting 1920 by 1080 frames out of it without issue. In fact, if you take only a single frame, you can go all the way to 2304 by 1536 with the C920 camera. I'm not sure why it fails when the grabber.grab's come in a faster clip, but it does manage to auto-change down to 1920x1080 and work correctly. The internals of this decision are opaque to me. The upshot: you should be good for 1920 x 1080.

I think the problem here is the the rows and columns are NOT the same as the number of pixels, there's some grouping of pixels to make up a column. Look more closely at those calculations.

edit flag offensive delete link more

Comments

hi professorguy, thanks for the above answer. In the above u had mentioned that there is no issue for u in 1920 by 1080. May i know the version of emgucv u had installed in ur application. thanks in advance, sorry for my poor english

karthick.j gravatar imagekarthick.j ( 2013-09-02 02:28:46 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-12-14 18:58:27 -0500

Seen: 2,702 times

Last updated: Dec 31 '12