symisc on master
docs: fix simple typo, accomida… Merge pull request #26 from tim… (compare)
I need to have have images in mat format to process further.
ConvertBitmapToRGBAMat function works correctly as I have verified it by saving generated grayscale image on device.
Giving my code below.
extern "C"
JNIEXPORT jobject JNICALL
Java_com_sodDetection(JNIEnv *env, jobject instance, jobject bitmap) {
cv::Mat rgbaMat;
cv::Mat grayMat;
jniutils::ConvertBitmapToRGBAMat(env, bitmap, rgbaMat, true);
cv::cvtColor(rgbaMat, grayMat, cv::COLOR_RGBA2GRAY);
sod_realnet *pNet; /* Realnet handle */
int i,rc;
/*
* Allocate a new RealNet handle */
rc = sod_realnet_create(&pNet);
if (rc != SOD_OK) return reinterpret_cast<jobject>(rc);
/*
* Register and load a RealNet model.
* You can train your own RealNet model on your CPU using the training interfaces [sod_realnet_train_start()]
* or download pre-trained models like this one from https://pixlab.io/downloads
*/
rc = sod_realnet_load_model_from_disk(pNet, "/storage/emulated/0/face.realnet.sod", 0);
if (rc != SOD_OK) return reinterpret_cast<jobject>(rc);
IplImage* imgipl = new IplImage(grayMat);
sod_img img = sod_img_load_cv_ipl(imgipl);
/// sod_img img = sod_img_load_grayscale(zFile);
if (img.data == 0) {
puts("Cannot load image");
return 0;
}
unsigned char *zBlob = sod_image_to_blob(img);
/*
* Bounding boxes array
*/
sod_box *aBoxes;
int nbox;
/*
* Perform Real-Time detection on this blob
*/
rc = sod_realnet_detect(pNet, zBlob, img.w, img.h, &aBoxes, &nbox);
if (rc != SOD_OK) return reinterpret_cast<jobject>(rc);
/* Consume result */
printf("%d potential face(s) were detected..\n", nbox);
for (i = 0; i < nbox; i++) {
/* Ignore low score detection */
if (aBoxes[i].score < 5.0) continue;
/* Report current object */
printf("(%s) x:%d y:%d w:%d h:%d prob:%f\n", aBoxes[i].zName, aBoxes[i].x, aBoxes[i].y, aBoxes[i].w, aBoxes[i].h, aBoxes[i].score);
/* Draw a rose box on the target coordinates */
// sod_image_draw_bbox_width(color, aBoxes[i], 3, 255., 0, 225.);
//sod_image_draw_circle(color, aBoxes[i].x + (aBoxes[i].w / 2), aBoxes[i].y + (aBoxes[i].h / 2), aBoxes[i].w, 255., 0, 225.);
}
// std::cout<<"time daken to detect "<<(clock()-(float)t)/CLOCKS_PER_SEC<<std::endl;
/ Save the detection result /
// sod_img_save_as_png(color, "/storage/emulated/0/yoyo.png");
/ cleanup /
sod_free_image(img);
// sod_free_image(color);
sod_image_free_blob(zBlob);
sod_realnet_destroy(pNet);
return bitmap;
}