Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

automatically resolution change (logitech c920)

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).

The other thing is that it will not change to the desired MJPEG compression. I tried:

cap.set(CV_CAP_PROP_FOURCC, 'M', 'J', 'P', 'G');

whcih outputs that there are to many parameters

cap.set(CV_CAP_PROP_FOURCC, 2);

This leads to following output:

HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(6) - Invalid argument

Would be great to get your help. I appreciate any suggestions



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();
        }
}

Wrong automatically set resolution change (logitech c920)(video capture)

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).c920). How can I see which resolutions are supported?

The other thing is that it will not change to the desired MJPEG compression. I tried:

cap.set(CV_CAP_PROP_FOURCC, 'M', 'J', 'P', 'G');

whcih outputs that there are to many parameters

cap.set(CV_CAP_PROP_FOURCC, 2);

This leads to following output:

HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(6) - Invalid argument

Would be great to get your help. I appreciate any suggestions



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();
        }
}

Wrong automatically set resolution (video capture)

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?

The other thing is that it will not change to the desired MJPEG compression. I tried:

cap.set(CV_CAP_PROP_FOURCC, 'M', 'J', 'P', 'G');

whcih outputs that there are to many parameters

cap.set(CV_CAP_PROP_FOURCC, 2);

This leads to following output:

HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(6) - Invalid argument

Would be great to get your help. I appreciate any suggestions



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();
        }
}

Wrong automatically set resolution (video capture)

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();
        }
}