void BlobDetection::handleOnImageReceived(const sensor_msgs::ImageConstPtr &msg) { auto image = cv_bridge::toCvShare(msg, "bgr8")->image; showImage(image, "original"); cv::Mat lightCorrectedImage; pCorrection->correct(image, lightCorrectedImage); // showImage(lightCorrectedImage, "corrected", true); detectWalls(image, msg->header.stamp); auto results = detectObjects(lightCorrectedImage); for (auto& result : results) { object_detection_blob::BlobObject rmsg; rmsg.header.seq++; rmsg.header.stamp = msg->header.stamp; rmsg.header.frame_id = "image"; rmsg.object_type = result.sType; rmsg.center_x = result.sObjectRect.center.x; rmsg.center_y = result.sObjectRect.center.y; rmsg.size_x = result.sObjectRect.size.width; rmsg.size_y = result.sObjectRect.size.height; rmsg.img_width = lightCorrectedImage.cols; rmsg.img_height = lightCorrectedImage.rows; objectPublisher.publish(rmsg); } }
void FindLargestObject(const cv::Mat &img, cv::CascadeClassifier &cascade, cv::Rect &largestObject, int scaledWidth) { int flags = cv::CASCADE_FIND_BIGGEST_OBJECT; Size minFeatureSize = Size(20, 20); float searchScaleFactor = 1.1f; int minNeighbors = 3; std::vector<cv::Rect> objects; detectObjects(img, cascade, objects, scaledWidth, flags, minFeatureSize, searchScaleFactor, minNeighbors); if (objects.size() > 0) { largestObject = (cv::Rect)objects.at(0); } else { largestObject = cv::Rect(-1,-1,-1,-1); } }
int hrt_main (int argc, char **argv) { int flag; int i; // detection parameters float scaleFactor = 1.2; int minNeighbours = 3; int size; printf("-- entering main function --\r\n"); printf("-- loading image --\r\n"); MyImage imageObj; MyImage *image = &imageObj; flag = readPgm((char *)INPUT_FILENAME, image); if (flag == -1) { printf( "Unable to open input image\n"); return 1; } printf("-- loading cascade classifier --\r\n"); myCascade cascadeObj; myCascade *cascade = &cascadeObj; MySize minSize = {20, 20}; MySize maxSize = {0, 0}; // classifier properties cascade->n_stages=25; cascade->total_nodes=2913; cascade->orig_window_size.height = 24; cascade->orig_window_size.width = 24; readTextClassifier(cascade); struct MyRect *result[NUM] = {}; //Load the program hrt_cell_load_program_id(CELL, haar); hrt_scalar_store(CELL, MyImage, myimage, image); hrt_indexed_store(CELL, MySize, mysize, 0, minSize); hrt_indexed_store(CELL, MySize, mysize, 1, maxSize); hrt_scalar_store(CELL, myCascade, mycascade, cascade); hrt_scalar_store(CELL, float, scalefactor, scaleFactor); hrt_scalar_store(CELL, int, minneighbours, minNeighbours); hrt_scalar_store(CELL, MyRect, myrect, result); printf("-- detecting faces --\r\n"); //size = detectObjects(image, minSize, maxSize, cascade, scaleFactor, minNeighbours, result); detectObjects(); size = hrt_scalar_load(CELL, int, size); printf("-- drawing boxes --\r\n"); for(i = 0; i < NUM; i++ ) { if ( result[i] != NULL) { struct MyRect *r = result[i]; drawRectangle(image, r); } else break; } printf("-- saving output --\r\n"); flag = writePgm((char *)OUTPUT_FILENAME, image); printf("-- image saved --\r\n"); // delete image and free classifier releaseTextClassifier(cascade); freeImage(image); return 0; }