können Sie cv_image verwenden von Mat zu konvertieren Bild DLIB und dlib::toMat von DLIB zu konvertieren Matte.
//Mat to dlib image
cv_image<bgr_pixel> dlib_img(mat);
Edit:
Soweit ich weiß, für n-Kanal-Mats Sie haben individuelle pixel_traits
zur Verfügung zu stellen. Zum Beispiel für eine 5-Kanal-Mat Bild können Sie tun:
namespace dlib{
struct custom_pixel
{
custom_pixel (
) {}
custom_pixel (
unsigned char c1_,
unsigned char c2_,
unsigned char c3_,
unsigned char c4_,
unsigned char c5_
) : c1(c1_), c2(c2_), c3(c3_), c4(c4_), c5(c5_) {}
unsigned char c1;
unsigned char c2;
unsigned char c3;
unsigned char c4;
unsigned char c5;
};
template <>
struct pixel_traits<custom_pixel>
{
constexpr static bool rgb = false;
constexpr static bool rgb_alpha = false;
constexpr static bool grayscale = false;
constexpr static bool hsi = false;
constexpr static bool lab = false;
enum { num = 5};// provide number of channels here
typedef unsigned char basic_pixel_type; //provide channel depth here
static basic_pixel_type min() { return 0;}
static basic_pixel_type max() { return 255;}
constexpr static bool is_unsigned = true;
constexpr static bool has_alpha = false;
};
}
Dann von Mat zu DLIB und umge zu konvertieren kehrt:
int main(int argc, char** argv)
{
// from opencv to dlib
Mat mat_img = Mat::zeros(3, 3, CV_8UC(5));
cv_image<custom_pixel> dlib_img(mat_img);
//from dlib to opencv
Mat mat_img_new = dlib::toMat(dlib_img);
}
Das über das, was Sie schreiben, nicht anwendbar ist, weil bgr_pixel für ist 3-Kanal-Bild, ich brauche eine Konvertierung für Bild/Matrix mit 192 Kanälen. – gulliver
@gulliver Siehe die Änderung. – zindarod
Ich habe so etwas versucht, aber dlib braucht etwas als nächstes. Das oben ist für die Umwandlung in cv_image, aber ich brauche Umstellung auf DLIB :: matrix.When ich versuche: cv_image cimg (mat); Matrix dm; assign_image (dm, cimg); Dies wird einen Fehler verursachen: keine Anpassungsfunktion für Aufruf ‚Assign (DLIB :: big_pixel &, const DLIB :: big_pixel &)‘) {assign_pixel_helpers :: zuweisen (DEST, src); } –
gulliver