Skip to content

Instantly share code, notes, and snippets.

@prabindh
Created August 27, 2018 12:15
Show Gist options
  • Save prabindh/b7875557e736f75a576972de5618aecf to your computer and use it in GitHub Desktop.
Save prabindh/b7875557e736f75a576972de5618aecf to your computer and use it in GitHub Desktop.
Resize changes
bool ArapahoV2::Detect(
const cv::Mat & inputMat,
float thresh,
float hier_thresh,
int & objectCount)
{
int count = 0;
objectCount = 0;
threshold = thresh;
// Early exits
if (!bSetup)
{
EPRINTF("Not Setup!\n");
return false;
}
if (inputMat.empty())
{
EPRINTF("Error in inputImage! [bgr = %d, w = %d, h = %d]\n",
!inputMat.data, inputMat.cols != net->w,
inputMat.rows != net->h);
return false;
}
//Convert to rgb
cv::Mat inputRgb;
cvtColor(inputMat, inputRgb, CV_BGR2RGB);
// Convert the bytes to float
cv::Mat floatMat;
inputRgb.convertTo(floatMat, CV_32FC3, 1 / 255.0);
cv::Mat resizedFloatMat = floatMat;
if (floatMat.rows != net->h || floatMat.cols != net->w)
{
DPRINTF("Detect: Resizing image to match network \n");
resize(floatMat, resizedFloatMat, cv::Size(net->w, net->h));
}
if (resizedFloatMat.channels() != 3)
{
EPRINTF("Detect: channels = %d \n", resizedFloatMat.channels());
return false;
}
// Get the image to suit darknet
cv::Mat floatMatChannels[3];
cv::Mat planarFloatMatTemp, planarFloatMat;
cv::split(resizedFloatMat, floatMatChannels);
vconcat(floatMatChannels[0], floatMatChannels[1], planarFloatMatTemp);
vconcat(planarFloatMatTemp, floatMatChannels[2], planarFloatMat);
__Detect((float*)planarFloatMat.data, thresh, hier_thresh, objectCount);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment