cv::Rect in a struct pack - unpack
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_
what is the best practices for above vector of struct pack and unpack in C++
Best
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
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);
};`
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 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
I don't know about zmq.
See https://stackoverflow.com/help/minimal-reproducible-example
See also https://github.com/msgpack/msgpack/blob/master/spec.md Check msgpack format using something like hex dump. Then fix your code.
@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);
};`