You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
4.8 KiB
184 lines
4.8 KiB
#include "darknetDetector.h"
|
|
|
|
darknetDetector::darknetDetector(){
|
|
m_dArea = 20.0;
|
|
m_iSST = 1;
|
|
m_iCounterSST = 0;
|
|
m_iWindow = 0;
|
|
m_iCounterWindow = 0;
|
|
m_bPIP = false;
|
|
m_bDilatePicture = false;
|
|
m_fThresh = .24f;
|
|
m_fHier_Thresh = .5f;
|
|
|
|
//m_sOptions = read_data_cfg("data/cfg/voc.data");
|
|
m_vNames = get_labels("data/voc.names");
|
|
//m_vAlphabet = load_alphabet();
|
|
|
|
//m_oNeuralNetwork = parse_network_cfg("data/cfg/tiny-yolo-voc.cfg");
|
|
m_oNeuralNetwork = parse_network_cfg("data/cfg/tiny-yolo.cfg");
|
|
//load_weights(&m_oNeuralNetwork, "data/tiny-yolo-voc.weights");
|
|
load_weights(&m_oNeuralNetwork, "data/tiny-yolo.weights");
|
|
set_batch_network(&m_oNeuralNetwork, 1);
|
|
srand(2222222);
|
|
|
|
//image im = load_image_color(input, 0, 0);
|
|
//image sized;
|
|
//sized.c = 3;
|
|
m_iHeight = m_oNeuralNetwork.h;
|
|
m_iWidth = m_oNeuralNetwork.w;
|
|
//m_oMat = cv::Mat(m_iHeight, m_iWidth, CV_32FC3);
|
|
//sized.data = (float*)m_oMat.data;
|
|
|
|
m_lLastLayer = m_oNeuralNetwork.layers[m_oNeuralNetwork.n - 1];
|
|
int j;
|
|
m_pBoxes = (box*)calloc(m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n, sizeof(box));
|
|
m_vProbs = (float**)calloc(m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n, sizeof(float *));
|
|
for (j = 0; j < m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n; ++j) m_vProbs[j] = (float*)calloc(m_lLastLayer.classes + 1, sizeof(float *));
|
|
m_vMasks = NULL;
|
|
if (m_lLastLayer.coords > 4){
|
|
m_vMasks = (float**)calloc(m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n, sizeof(float*));
|
|
for (j = 0; j < m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n; ++j) m_vMasks[j] = (float*)calloc(m_lLastLayer.coords - 4, sizeof(float *));
|
|
}
|
|
};
|
|
|
|
darknetDetector::~darknetDetector(){
|
|
};
|
|
|
|
void darknetDetector::setParametersEx(int SST, int DetectionWindow){
|
|
m_iSST = SST;
|
|
m_iWindow = DetectionWindow;
|
|
};
|
|
|
|
bool darknetDetector::m_fImageAnalyzer(Mat &Picture){
|
|
if( Picture.cols > 0 && Picture.rows > 0 ){
|
|
m_mBufferProtectorMutex.lock();
|
|
Mat tMat = cv::Mat(m_iHeight, m_iWidth, CV_8UC3);
|
|
Picture.copyTo(m_oMat);
|
|
Picture.copyTo(tMat);
|
|
resize(tMat, tMat, Size(m_iWidth, m_iHeight), 0.0, 0.0, INTER_AREA);
|
|
//cvtColor( tMat, tMat, CV_RGB2GRAY );
|
|
IplImage *tIPL;
|
|
tIPL = new IplImage(tMat);
|
|
DN::image im;
|
|
im = DN::ipl_to_image(tIPL);
|
|
network_predict(m_oNeuralNetwork, (float*)im.data );
|
|
m_mBufferProtectorMutex.unlock();
|
|
};
|
|
return true;
|
|
};
|
|
|
|
|
|
void darknetDetector::markup(Mat &Picture){
|
|
float nms = .3f;
|
|
//char Buffer[20];
|
|
//sprintf(Buffer, "Motion Detected");
|
|
//rectangle(Picture, Point(Picture.cols - 120, 5), Point(Picture.cols - 10, 15), Scalar(0, 0, 255), CV_FILLED);
|
|
//putText(Picture, Buffer, Point(Picture.cols - 115, 13), FONT_HERSHEY_SIMPLEX, 0.3, Scalar(255, 0, 0), 1);
|
|
m_mBufferProtectorMutex.lock();
|
|
get_region_boxes(
|
|
m_lLastLayer,
|
|
Picture.cols,
|
|
Picture.rows,
|
|
m_oNeuralNetwork.w,
|
|
m_oNeuralNetwork.h,
|
|
m_fThresh,
|
|
m_vProbs,
|
|
m_pBoxes,
|
|
m_vMasks,
|
|
0,
|
|
0,
|
|
m_fHier_Thresh,
|
|
1
|
|
);
|
|
if (nms)
|
|
do_nms_obj(
|
|
m_pBoxes,
|
|
m_vProbs,
|
|
m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n,
|
|
m_lLastLayer.classes,
|
|
nms
|
|
);
|
|
//else if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
|
|
/*
|
|
IplImage *tIPL;
|
|
//tIPL = new IplImage(Picture);
|
|
tIPL = new IplImage(m_oMat);
|
|
DN::image im;
|
|
im = DN::ipl_to_image(tIPL);
|
|
draw_detections(
|
|
im,
|
|
m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n,
|
|
m_fThresh,
|
|
m_pBoxes,
|
|
m_vProbs,
|
|
m_vMasks,
|
|
m_vNames,
|
|
m_vAlphabet,
|
|
m_lLastLayer.classes
|
|
);
|
|
//IplImage *tIPL2;
|
|
tIPL = new IplImage(Picture);
|
|
|
|
DN::image_into_ipl(im, tIPL);
|
|
*/
|
|
m_oMat.copyTo(Picture);
|
|
drawMAT_detections(
|
|
Picture,
|
|
m_lLastLayer.w*m_lLastLayer.h*m_lLastLayer.n,
|
|
m_fThresh,
|
|
m_pBoxes,
|
|
m_vProbs,
|
|
m_vMasks,
|
|
m_vNames,
|
|
m_lLastLayer.classes
|
|
);
|
|
m_mBufferProtectorMutex.unlock();
|
|
};
|
|
|
|
|
|
/*
|
|
|
|
#include <cv.h>
|
|
#include <highgui.h>
|
|
#include <iostream>
|
|
|
|
using namespace cv;
|
|
|
|
int main( int argc, char** argv )
|
|
{
|
|
double alpha = 0.5; double beta; double input;
|
|
|
|
Mat src1, src2, dst;
|
|
|
|
/// Ask the user enter alpha
|
|
std::cout<<" Simple Linear Blender "<<std::endl;
|
|
std::cout<<"-----------------------"<<std::endl;
|
|
std::cout<<"* Enter alpha [0-1]: ";
|
|
std::cin>>input;
|
|
|
|
/// We use the alpha provided by the user if it is between 0 and 1
|
|
if( input >= 0.0 && input <= 1.0 )
|
|
{ alpha = input; }
|
|
|
|
/// Read image ( same size, same type )
|
|
src1 = imread("../../images/LinuxLogo.jpg");
|
|
src2 = imread("../../images/WindowsLogo.jpg");
|
|
|
|
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
|
|
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
|
|
|
|
/// Create Windows
|
|
namedWindow("Linear Blend", 1);
|
|
|
|
beta = ( 1.0 - alpha );
|
|
addWeighted( src1, alpha, src2, beta, 0.0, dst);
|
|
|
|
imshow( "Linear Blend", dst );
|
|
|
|
waitKey(0);
|
|
return 0;
|
|
}
|
|
|
|
|
|
*/
|