int ann_train( CvANN_MLP* ann, CvMLData* _data, Mat& new_responses, CvANN_MLP_TrainParams _params, int flags = 0 ) { const CvMat* train_sidx = _data->get_train_sample_idx(); CvMat predictors; ann_check_data_and_get_predictors( _data, &predictors ); CvMat _new_responses = CvMat( new_responses ); return ann->train( &predictors, &_new_responses, 0, train_sidx, _params, flags ); }
float ann_calc_error( CvANN_MLP* ann, CvMLData* _data, map<int, int>& cls_map, int type , vector<float> *resp_labels ) { float err = 0; const CvMat* responses = _data->get_responses(); const CvMat* sample_idx = (type == CV_TEST_ERROR) ? _data->get_test_sample_idx() : _data->get_train_sample_idx(); int* sidx = sample_idx ? sample_idx->data.i : 0; int r_step = CV_IS_MAT_CONT(responses->type) ? 1 : responses->step / CV_ELEM_SIZE(responses->type); CvMat predictors; ann_check_data_and_get_predictors( _data, &predictors ); int sample_count = sample_idx ? sample_idx->cols : 0; sample_count = (type == CV_TRAIN_ERROR && sample_count == 0) ? predictors.rows : sample_count; float* pred_resp = 0; vector<float> innresp; if( sample_count > 0 ) { if( resp_labels ) { resp_labels->resize( sample_count ); pred_resp = &((*resp_labels)[0]); } else { innresp.resize( sample_count ); pred_resp = &(innresp[0]); } } int cls_count = (int)cls_map.size(); Mat output( 1, cls_count, CV_32FC1 ); CvMat _output = CvMat(output); map<int, int>::iterator b_it = cls_map.begin(); for( int i = 0; i < sample_count; i++ ) { CvMat sample; int si = sidx ? sidx[i] : i; cvGetRow( &predictors, &sample, si ); ann->predict( &sample, &_output ); CvPoint best_cls = {0,0}; cvMinMaxLoc( &_output, 0, 0, 0, &best_cls, 0 ); int r = cvRound(responses->data.fl[si*r_step]); CV_DbgAssert( fabs(responses->data.fl[si*r_step]-r) < FLT_EPSILON ); r = cls_map[r]; int d = best_cls.x == r ? 0 : 1; err += d; pred_resp[i] = (float)best_cls.x; } err = sample_count ? err / (float)sample_count * 100 : -FLT_MAX; return err; }
int main(void) { printf("ORF pid %d\n", (int) getpid()); SRCAM cam; // int ret = SR_OpenDlg(&cam, 2, 0); // 2: call open dialog, 0: no parent window // int ret = SR_OpenETH(&cam, "192.168.1.33"); int ret = SR_OpenETH(&cam, "169.254.1.33"); if(ret<=0) return -1; // ret holds the number of cameras found cv::Size imsize(SR_GetCols(cam), SR_GetRows(cam)); // SR image size int sizebytes = 2 * imsize.area() * sizeof(unsigned short); // number of bytes sent from the SR // namedWindow("mainWin",WINDOW_AUTOSIZE ); cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); int sizestep = sizeof(float)*3; // size step from one xyz component to the next int c=-1; // user input variable // enable software trigger mode so that the LEDs will only turn // on when SR_Acquire() is called SR_SetMode(cam,AM_SW_TRIGGER); std::time_t start_time = std::time(0); while(c==-1) // infinite loop, breaks if key pressed { ret = SR_Acquire(cam); cv::Mat xyz(imsize, CV_32FC3, cv::Scalar::all(0)); if(ret!=sizebytes) break; // the coordinates are stored as three channels in the format // (x1, y1, z1, x2, y2, z2, ... ) squentially row by row SR_CoordTrfFlt( cam, &((float*)xyz.ptr())[0], // pointer to first x &((float*)xyz.ptr())[1], // pointer to first y &((float*)xyz.ptr())[2], // pointer to first z sizestep, sizestep, sizestep); // increments to next element cv::Mat z, z_display; // z channel and output image extractImageCOI(&CvMat(xyz), z, 2); // extract the z channel (change the 2 for another channel) z.convertTo(z_display, CV_8UC1, 256.0 / 5.0, 0); // convert to 8 bit (0..255) values, here for 5 meter camera cv::imshow("mainWin", z_display); // display image std::time_t t = std::time() - start_time; printf("ORF data taken at %d seconds\n", t); //std::cout << "ORF data taken at" << t << "seconds\n"; std::stringstream filename; filename << "./ORF_photos/" << t << ".bmp" cv::imwrite(filename.str(),z_display); c = cvWaitKey(1000); // wait 1 sec before continuing loop. if user presses a button, the loop will exit } SR_Close(cam); return 0; }
void boxtrackproperties:: correct(const cv::Mat &m) { //m, measurement cv::Mat_<float>(5,1) CvMat _z=CvMat(m); cvKalmanCorrect(k,&_z); }