Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv::Rect in a struct pack - unpack #1052

Open
MyraBaba opened this issue Feb 26, 2023 · 8 comments
Open

cv::Rect in a struct pack - unpack #1052

MyraBaba opened this issue Feb 26, 2023 · 8 comments

Comments

@MyraBaba
Copy link

Hi,

I have below struct and msg_pack:


struct  AlpBox 
{

cv::Rect  bbox;
double    confidence;
int       class_id;
MSGPACK_DEFINE(bbox,confidence,class_id);

} ;

struct Alpdetections
{
  std::vector<AlpBox>  detections;
  MSGPACK_DEFINE(detections)
}


it gives :

                                                                     │··········

../libs/postprocesses/alpullu/messaging.h:32:1: required from here │··········
/usr/local/include/msgpack/v1/object.hpp:647:7: error: ‘class cv::Rect_’ has no member named ‘msgpack_unpa│··········
ck’ │··········
647 | v.msgpack_unpack(o.convert());

what is the best practices for above vector of struct pack and unpack in C++

Best

@redboltz
Copy link
Contributor

You need to prepare the adaptor for cv::Rect. The error message means cv::Rect doesn't have an adaptor.
You can define the adaptor for cv::Rect as
https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-intrusive-approach

@MyraBaba
Copy link
Author

@redboltz

Hi Again,

Is below approach is correct? I want to send AlpDetectionsthrough zmq


`struct  AlpBox 
{
int p1 ,p2 ,p3 ,p4 ;
float    confidence;
int       class_id;
MSGPACK_DEFINE(p1 ,p2 ,p3 ,p4,confidence,class_id);

}  ;

struct AlpDetections
{
  std::vector<AlpBox>  detections;
  MSGPACK_DEFINE(detections);
};`

@redboltz
Copy link
Contributor

@MyraBaba
Copy link
Author

@redboltz for above struct:


`
std::vector<AlpulluBox>  alpdetections;
  AlpulluBox alpbbox;
            float confidence   = detection->get_confidence();
            int class_id     = detection->get_class_id();
            alpbbox ={xmin,ymin,xmax,ymax , detection->get_confidence() , detection->get_class_id()};
            alpdetections.push_back(alpbbox);

         }
    }

   msgpack::sbuffer seriailezAlpDetections;
   msgpack::pack(&seriailezAlpDetections, alpdetections );`

deserializing ::

zmq::message_t contents;
//zmq::recv_result_t result = subscriber.recv(contents);

            zmq::message_t response_data;
            subscriber.recv(response_data, zmq::recv_flags::none);
            msgpack::unpacked unpacked_response_data;
            msgpack::unpack(unpacked_response_data,
                            static_cast<const char*>(response_data.data()),
                            response_data.size());

            auto unpacked_response = unpacked_response_data.get().as<AlpulluBox>();

gives erro r:

: terminating with uncaught exception of type msgpack::v1::type_error: std::bad_cast

@redboltz
Copy link
Contributor

I don't know about zmq.

@redboltz
Copy link
Contributor

@redboltz
Copy link
Contributor

See also https://github.com/msgpack/msgpack/blob/master/spec.md
Check msgpack format using something like hex dump.
Then fix your code.

@MyraBaba
Copy link
Author

@can we directly cast to the coming object for AlpDetection ?


struct  AlpBox 
{
int p1 ,p2 ,p3 ,p4 ;
float    confidence;
int       class_id;
MSGPACK_DEFINE(p1 ,p2 ,p3 ,p4,confidence,class_id);

}  ;

struct AlpDetections
{
  std::vector<AlpBox>  detections;
  MSGPACK_DEFINE(detections);
};`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants