I assume that the result of buf.read() is true, so you're sure the image was
read in the first place?
It's only a guess, but it's possible that OpenCV support was not enabled at
build time for OpenImageIO. It needs to find the OpenCV headers and library
when OpenImageIO itself is built, or else the to_OpenCV and from_OpenCV
functions always just return false and don't try to do anything.
I see now that there isn't an especially good way of knowing this from the
built library. I will add something to make it easier to find out (without
being the builder yourself) whether your copy of OIIO has OpenCV support
enabled.
As an unrelated aside, you should change
using namespace OpenImageIO_v2_4;
to
using namespace OIIO;
OIIO is always an alias for the fully versioned namespace. But then you don't
need to update your source code for different versions of OpenImageIO.
> On May 27, 2023, at 10:08 AM, juneleungchan <[email protected]> wrote:
>
>
> Hello,
>
> Thanks for your great work of OIIO.
>
> I have a question when using OIIO and wanna to ask how to use with details.
> I'm not sure if I'm writing to this email address is the right channel to ask
> questions. If not, please point me to it, thanks.
>
>
> My question is about how to convert between OIIO's buf and Opencv. I found
> related functions (ImageBufAlgo::to_OpenCV and ImageBufAlgo::from_OpenCV) in
> the manual, but it seems that I always get a false result for these the
> result of functions .
>
> I would like to ask if I am using it correctly, and is there any sample for
> reference?
>
> my code:
> ```
> #include <OpenImageIO/imagebuf.h>
> #include <OpenImageIO/imagebufalgo.h>
> #include <OpenImageIO/Imath.h>
> #include <OpenImageIO/imagecache.h>
> #include <OpenImageIO/imageio.h>
> using namespace OpenImageIO_v2_4;
> using namespace cv;
>
> QString img = “./0003.png";
> ImageBuf buf(img.toStdString());
> bool ok = buf.read (0, 0, true, TypeDesc::FLOAT); // true
>
> auto Mat1 = cv::Mat {};
> bool succ = ImageBufAlgo::to_OpenCV(Mat1, buf);
> qDebug()<< succ ;// false
>
> ```
>
>
> Functions I found:
>
> OpenCV interoperability is performed by the from_OpenCV() and to_OpenCV()
> functions:
> ImageBuf OIIO::ImageBufAlgo::from_OpenCV(const cv::Mat &mat, TypeDesc
> <https://openimageio.readthedocs.io/en/latest/imageioapi.html#_CPPv4N4OIIO8TypeDescE>
> convert = TypeUnknown, ROI
> <https://openimageio.readthedocs.io/en/latest/imageioapi.html#_CPPv4N4OIIO3ROIE>
> roi = {}, int nthreads = 0)
> Convert an OpenCV cv::Mat into an ImageBuf, copying the pixels (optionally
> converting to the pixel data type specified by convert, if not UNKNOWN, which
> means to preserve the original data type if possible). Return true if ok,
> false if it couldn’t figure out how to make the conversion from Mat to
> ImageBuf. If OpenImageIO was compiled without OpenCV support, this function
> will return an empty image with error message set.
> bool OIIO::ImageBufAlgo::to_OpenCV(cv::Mat &dst, const ImageBuf &src, ROI
> <https://openimageio.readthedocs.io/en/latest/imageioapi.html#_CPPv4N4OIIO3ROIE>
> roi = {}, int nthreads = 0)
> Construct an OpenCV cv::Mat containing the contents of ImageBuf src, and
> return true. If it is not possible, or if OpenImageIO was compiled without
> OpenCV support, then return false. Note that OpenCV only supports up to 4
> channels, so >4 channel images will be truncated in the conversion.
>
> Looking forward to your reply and thanks very much.
>
> Juneleung
> May 28 2023
>
>
> Juneleung
> TD
> [email protected]
>
> <https://dashi.163.com/projects/signature-manager/detail/index.html?ftlId=3&name=Juneleung&uid=juneleungchan%40163.com&iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fwzpmmc%2F3ef565873cb038cd2c89818903cf0fcc.jpg&email=Juneleungchan%40163.com&position=TD&items=%5B%22Juneleungchan%40163.com%22%5D>
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org