ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
SivamPillai already pointed out that there is a difference between the cvXXX
functions that still use IplImage
and are part of the C interface of OpenCV and the cv::XXX
functions that use cv::Mat
as data type and are part of the C++ interface. Whenever you get an error where a function needs a const CvArr*
argument, you are probably giving it a cv::Mat
instead of an IplImage
. I would recommend looking for the C++ equivalent of that function and completely avoiding IplImage
as cv::Mat
is much more flexible.
About the errors:
You seem to be confusing the CvImagePtr
types and the OpenCV type cv::Mat
. If you want to process the image from the message in OpenCV after you have it copied and encoded in cv_ptr
you should assign the data to an actual cv::Mat
doing something like
cv::Mat imageColor = cv_ptr->image;
image
is the member of CvImagePtr
that contains the actual image data. It also contains the header of the image message and the encoding. You don't have to worry about that since the encoding (without the channel order though) is already covered in the type
of the cv::Mat
.
If you use the above line, you should be able to do something like
std::vector<cv::Mat> channels;
cv::split(imageColor, channels);
// And then if you like
cv::Mat imageB = channels[0];
cv::Mat imageG = channels[1];
cv::Mat imageR = channels[2];
This should give you the separate channels. If you display the with cv::imshow
you will see three gray images of course.
You can then apply the threshold function as it is explained here.
2 | No.2 Revision |
SivamPillai already pointed out that there is a difference between the cvXXX
functions that still use IplImage
and are part of the C interface of OpenCV and the cv::XXX
functions that use cv::Mat
as data type and are part of the C++ interface. Whenever you get an error where a function needs a const CvArr*
argument, you are probably giving it a cv::Mat
instead of an IplImage
. I would recommend looking for the C++ equivalent of that function and completely avoiding IplImage
as cv::Mat
is much more flexible.
About the errors:
You seem to be confusing the CvImagePtr
types and the OpenCV type (defined in cv_bridge) and cv::Mat
. cv::Mat
(defined in OpenCV). If you want to process the image from contained in the message in OpenCV after you have it copied and encoded in cv_ptr
, you should assign the data to an actual cv::Mat
doing something like
cv::Mat imageColor = cv_ptr->image;
image
is the member of CvImagePtr
that contains the actual image data. It also contains the header of the image message and the encoding. You don't have to worry about that since the encoding (without the channel order though) is already covered in the type
of the cv::Mat
.
If you use the above line, you should be able to do something like
std::vector<cv::Mat> channels;
cv::split(imageColor, channels);
// And then if you like
cv::Mat imageB = channels[0];
cv::Mat imageG = channels[1];
cv::Mat imageR = channels[2];
This should give you the separate channels. If you display the with cv::imshow
you will see three gray images of course.
You can then apply the threshold function as it is explained here.
3 | No.3 Revision |
SivamPillai already pointed out that there is a difference between the cvXXX
functions that still use IplImage
and are part of the C interface of OpenCV and the cv::XXX
functions that use cv::Mat
as data type and are part of the C++ interface. Whenever you get an error where a function needs a const CvArr*
argument, you are probably giving it a cv::Mat
instead of an IplImage
. I would recommend looking for the C++ equivalent of that function and completely avoiding IplImage
as cv::Mat
is much more flexible.
About the errors:
You seem to be confusing the CvImagePtr
types (defined in cv_bridge) and cv::Mat
(defined in OpenCV). If you want to process the image contained in the message after you have it copied and encoded in cv_ptr
, you should assign the data to an actual cv::Mat
doing something like
cv::Mat imageColor = cv_ptr->image;
image
is the member of CvImagePtr
that contains the actual image data. data as a cv::Mat. It also contains the header of the image message and the encoding. You don't have to worry about that since the encoding (without the channel order though) is already covered in the type
of the cv::Mat
.
If you use the above line, you should be able to do something like
std::vector<cv::Mat> channels;
cv::split(imageColor, channels);
// And then if you like
cv::Mat imageB = channels[0];
cv::Mat imageG = channels[1];
cv::Mat imageR = channels[2];
This should give you the separate channels. If you display the with cv::imshow
you will see three gray images of course.
You can then apply the threshold function as it is explained here.
4 | No.4 Revision |
SivamPillai already pointed out that there is a difference between the cvXXX
functions that still use IplImage
and are part of the C interface of OpenCV and the cv::XXX
functions that use cv::Mat
as data type and are part of the C++ interface. Whenever you get an error where a function needs a const CvArr*
argument, you are probably giving it a cv::Mat
instead of an IplImage
. I would recommend looking for the C++ equivalent of that function and completely avoiding IplImage
as cv::Mat
is much more flexible.
About the errors:
You seem to be confusing the CvImagePtr
types (defined in cv_bridge) and cv::Mat
(defined in OpenCV). If you want to process the image contained in the message after you have it copied and encoded in cv_ptr
, you should assign the data to an actual cv::Mat
doing something like
cv::Mat imageColor = cv_ptr->image;
image
is the member of CvImagePtr
that contains the actual image data as a cv::Mat. It also contains the header of the image message and the encoding. You don't have to worry about that since the encoding (without the channel order though) is already covered in the type
of the cv::Mat
.
If you use the above line, you should be able to do something like
std::vector<cv::Mat> channels;
cv::split(imageColor, channels);
// And then if you like
cv::Mat imageB = channels[0];
cv::Mat imageG = channels[1];
cv::Mat imageR = channels[2];
This should give you the separate channels. If you display the them with cv::imshow
you will see three gray images of course.
You can then apply the threshold function as it is explained here.
5 | No.5 Revision |
SivamPillai already pointed out that there is a difference between the cvXXX
functions that still use IplImage
and are part of the C interface of OpenCV and the cv::XXX
functions that use cv::Mat
as data type and are part of the C++ interface. Whenever you get an error where a function needs a const CvArr*
argument, you are probably giving it a cv::Mat
instead of an IplImage
. I would recommend looking for the C++ equivalent of that function and completely avoiding IplImage
as cv::Mat
is much more flexible.
About the errors:
You seem to be confusing the CvImagePtr
types (defined in cv_bridge) and cv::Mat
(defined in OpenCV). If you want to process the image contained in the message after you have it copied and encoded in cv_ptr
, you should assign the data to an actual cv::Mat
doing something like
cv::Mat imageColor = cv_ptr->image;
image
is the member of CvImagePtr
that contains the actual image data as a cv::Mat. It CvImagePtr
also contains the header of the image message and the encoding. You don't have to worry about that since the encoding (without the channel order though) is already covered in the type
of the cv::Mat
.
If you use the above line, you should be able to do something like
std::vector<cv::Mat> channels;
cv::split(imageColor, channels);
// And then if you like
cv::Mat imageB = channels[0];
cv::Mat imageG = channels[1];
cv::Mat imageR = channels[2];
This should give you the separate channels. If you display them with cv::imshow
you will see three gray images of course.
You can then apply the threshold function as it is explained here.