Skip to content

Instantly share code, notes, and snippets.

@zihaomu
Last active July 27, 2022 08:06
Show Gist options
  • Save zihaomu/cfa4fb545fc9f4da9869b07f5dc95c3c to your computer and use it in GitHub Desktop.
Save zihaomu/cfa4fb545fc9f4da9869b07f5dc95c3c to your computer and use it in GitHub Desktop.
OpenCV print blob
//#define CV_8U 0
//#define CV_8S 1
//#define CV_16U 2
//#define CV_16S 3
//#define CV_32S 4
//#define CV_32F 5
//#define CV_64F 6
//#define CV_16F 7
void printblob(InputArray blob_) {
Mat blob = blob_.getMat();
auto shapeV = shape(blob);
auto typeMat = blob.type();
std::cout << "data type = " << typeMat << std::endl;
float *ptrf;
uchar *ptru;
char *ptrc;
int* ptrs;
int len = std::min(int(blob.total()), 10);
if (typeMat == 0) {
ptru = (uchar *) blob.data;
for (int i = 0; i < len; i++) {
std::cout << (int) *(ptru + i) << ", ";
}
}else if (typeMat == 1) {
ptrc = (char *)blob.data;
for(int i = 0; i<len; i++) {
std::cout<<(int) *(ptrc + i)<<", ";}
}else if (typeMat == 4) {
ptrs = (int *)blob.data;
for(int i = 0; i<len; i++) {
std::cout<<(int) *(ptrs + i)<<", ";}
}
else if (typeMat == 5) {
ptrf = (float *)blob.data;
for(int i = 0; i<len; i++) {
std::cout<<*(ptrf + i)<<", ";
}
}
std::cout<<std::endl;
}
void printShape(InputArray blob_)
{
Mat blob = blob_.getMat();
auto shapeA = shape(blob);
for (int i = 0; i < shapeA.size(); i++)
{
std::cout<<"x"<<shapeA[i];
}
std::cout<<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment