msgpack-c icon indicating copy to clipboard operation
msgpack-c copied to clipboard

cv::Rect in a struct pack - unpack

Open MyraBaba opened this issue 2 years ago • 8 comments

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

MyraBaba avatar Feb 26 '23 07:02 MyraBaba

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

redboltz avatar Feb 26 '23 08:02 redboltz

@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);
};`

MyraBaba avatar Feb 26 '23 09:02 MyraBaba

See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_tutorial and othre documents. and https://github.com/msgpack/msgpack-c/tree/cpp_master/example

redboltz avatar Feb 26 '23 10:02 redboltz

@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

MyraBaba avatar Feb 26 '23 13:02 MyraBaba

I don't know about zmq.

redboltz avatar Feb 26 '23 15:02 redboltz

See https://stackoverflow.com/help/minimal-reproducible-example

redboltz avatar Feb 26 '23 15:02 redboltz

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

redboltz avatar Feb 26 '23 15:02 redboltz

@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);
};`

MyraBaba avatar Feb 26 '23 16:02 MyraBaba