void printMD(cl_mem a, int m, int n){ int *x = malloc(sizeof(int)*m*n); clEnqueueReadBuffer(commands, a, CL_TRUE, 0, sizeof(int)*m*n, x, 0, NULL, NULL); clFinish(commands); printM(x, m, n); free(x); }
int main () { int n = 0; initM (); /** 一直训练直到能够100%正确为止 **/ while (1) { n ++; calcY (); int err = adjustM (); if (0 >= err) { /** 能够 100 %正确地回答问题了,结束训练 **/ break; } printf ("错误数 %d\n", err); } printM (); printf ("阈值: %d, 训练次数: %d\n", ST, n); while (1) { int a = 0; scanf ("%i", &a); if (0 > a || 9 < a) { break; } test (a); } return 0; }
void primM(int g[V][V]) { int parent[V]; int key[V]; bool mSet[V]; for (int i = 0; i < V; i++) key[i] = INT_MAX, mSet[i] = false; key[0] = 0; parent[0] = -1; for (int count = 0; count < V-1; count++) { int u = minKey(key, mSet); mSet[u] = true; for (int v = 0; v < V; v++) if (graph[u][v] && mSet[v] == false && g[u][v] < key[v]) parent[v] = u, key[v] = g[u][v]; } printM(parent, V, g); }
main(){ char str[50]; printf("Enter your name: "); gets(str); printW(); printf("\n"); delay(50); printE(); printf("\n"); delay(50); printL(); printf("\n"); delay(50); printC(); printf("\n"); delay(50); printO(); printf("\n"); delay(50); printM(); printf("\n"); delay(50); printE(); printf("\n"); delay(50); }
void main() { int a[LEN][LEN] /*= { { 1,0,0,0,0,0,0,0,0,0 }, { 0,1,0,0,0,0,0,0,0,0 }, { 0,0,1,0,0,0,0,0,0,0 }, { 0,0,0,1,0,0,0,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0 }, { 0,0,0,0,0,1,0,0,0,0 }, { 0,0,0,0,0,0,1,0,0,0 }, { 0,0,0,0,0,0,0,1,0,0 }, { 0,0,0,0,0,0,0,0,1,0 }, { 0,0,0,0,0,0,0,0,0,1 } }*/; initR(a); srand((unsigned)time(NULL)); int counter = 0; while( identity_matrix(&a[LEN][LEN],LEN) != 1 && counter < 2e16+1){ counter++; // printM(a); initR(a); } printM(a); printf("counter = %d\n",counter); printf("%d\n",identity_matrix(&a[LEN][LEN],LEN)); }
void printMarcel(int x, int y) { printM(x,y); printA(x+5*SIZE+GAP,y); printR(x+8*SIZE+2*GAP,y); printC(x+12*SIZE+3*GAP,y); printE(x+16*SIZE+4*GAP,y); printL(x+19*SIZE+5*GAP,y); }
void printWilliam(int x, int y) { printW(x,y); printI(x+5*SIZE+GAP,y); printL(x+6*SIZE+2*GAP,y); printL(x+9*SIZE+3*GAP,y); printI(x+12*SIZE+4*GAP,y); printA(x+13*SIZE+5*GAP,y); printM(x+16*SIZE+6*GAP,y); }
void printGameOver(int x, int y) { printG(x,y); printA(x+5*SIZE+GAP, y); printM(x+8*SIZE+2*GAP, y); printE(x+13*SIZE+3*GAP, y); printO(x+16*SIZE+5*GAP, y); printV(x+20*SIZE+6*GAP, y); printE(x+24*SIZE+7*GAP, y); printR(x+27*SIZE+8*GAP, y); }
int main(){ int i,n; extern int ndigit[]; n = 0; for(i = 0;i<10;i++){ ndigit[i] = -1; } while((n = getline()) > 0){ printM(); } return 0; }
/* Test with test.mat, but only with k = 2! (eigen vectors = (0.577, 0.577, 0.5770), (-0.707, 0, 0,707), and a mysterious third? eig values = (12, 6, 0) */ int main(int argc, char *argv[]) { if (argc != 6) { fprintf(stderr, "Error: wrong number of arguments provided. Program expects 5 arguments (k, log(epsilon), filename, matrix dimension n, mode). \n Mode 1 = read from file. Mode 2 = generate matrix. \n\n"); exit(1); } //int k = atoi(argv[1]); double epsilon = (double)atof(argv[2]); char *input = argv[3]; int n = atoi(argv[4]); int mode = atoi(argv[5]); //printf("\nRunning eigP with arguments (%i, %f, %s, %i)\n\n", k, epsilon, input, n); /* Get input matrix A */ double **A = newM(n, n); switch(mode) { case(1): A = readM(input, n, n); break; case(2): A = symRandomM(n); writeM(A, "test.mat", n, n); break; } printM(A, n, n); double **eVecs = newM(n, n); double *eVals = (double *)malloc(sizeof(double)*n); jacobi(A, eVecs, eVals, n, n); eVecs = sortEigenVecs(eVecs, eVals, n, n); // For Power method /*double *eVec1 = powerConverge(A, n, epsilon); printM(&eVec1, 1, n); eVecs = powerConvergeK(A, n, epsilon, k); eVals = eigenVals(A, eVecs, n); */ /* printf("Results:\n\n"); printM(eVecs, n, n); printM(&eVals, 1, n); */ writeM(eVecs, "eVecs.data", n, n); writeM(&eVals, "eVals.data", 1, n); return 0; }
void main() { int **MarrayA = (int **)malloc(sizeof(int *)*N); int **MarrayB = (int **)malloc(sizeof(int *)*N); int **Result = (int **)malloc(sizeof(int *)*N); int i,j; for(i=0;i<N;i++) { MarrayA[i] = (int *)malloc(sizeof(int)*N); MarrayB[i] = (int *)malloc(sizeof(int)*N); Result[i] = (int *)malloc(sizeof(int)*N); } for(i=0;i<N;i++) for(j=0;j<N;j++) { /*if(i==j) { MarrayA[i][j] = 1; MarrayB[i][j] = 1; }else { MarrayA[i][j] = 0; MarrayB[i][j] = 0; }*/ MarrayA[i][j] = rand()%10; MarrayB[i][j] = rand()%10; } printf("矩阵A\n"); printM(MarrayA,N); printf("矩阵B\n"); printM(MarrayB,N); StrassenM(MarrayA,MarrayB,Result,N); printf("结果:\n"); printM(Result,N); getchar(); }
void Calibration::device_config( OpticalDevice::Config *dev_config, string calib_path, string int_id, string size_id, string R_id, string T_id ) { CvMat* _int = (CvMat*)cvLoad( calib_path.c_str(), NULL, int_id.c_str() ); CvMat* _size = (CvMat*)cvLoad( calib_path.c_str(), NULL, size_id.c_str() ); CvMat* _R = (CvMat*)cvLoad( calib_path.c_str(), NULL, R_id.c_str() ); CvMat* _T = (CvMat*)cvLoad( calib_path.c_str(), NULL, T_id.c_str() ); if (ofGetLogLevel() == OF_LOG_VERBOSE) { ofLog(OF_LOG_VERBOSE, "\n cml::Calibration "+calib_path); ofLog( OF_LOG_VERBOSE, "intrinsics" ); printM( _int ); //ofLog( OF_LOG_VERBOSE, "R" ); //printM( _R ); //ofLog( OF_LOG_VERBOSE, "T" ); //printM( _T ); } device_config( dev_config, _size, _int, _R, _T ); cvReleaseMat( &_int ); cvReleaseMat( &_size ); cvReleaseMat( &_R ); cvReleaseMat( &_T ); };
void CamaraLucida::load_data(string kinect_calibration_filename, string proj_calibration_filename) { const char* kinect_calibration_filename_str = kinect_calibration_filename.c_str(); const char* proj_calibration_filename_str = proj_calibration_filename.c_str(); // rgb rgb_int = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "rgb_intrinsics"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n rgb_intrinsics opencv (kinect_calibration.yml)"); printM(rgb_int); calib.fx_rgb = (float)cvGetReal2D( rgb_int, 0, 0 ); calib.fy_rgb = (float)cvGetReal2D( rgb_int, 1, 1 ); calib.cx_rgb = (float)cvGetReal2D( rgb_int, 0, 2 ); calib.cy_rgb = (float)cvGetReal2D( rgb_int, 1, 2 ); CvMat* rgb_size = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "rgb_size"); calib.rgb_width = (int)cvGetReal2D( rgb_size, 0, 0 ); calib.rgb_height = (int)cvGetReal2D( rgb_size, 0, 1 ); cvReleaseMat(&rgb_size); convertKKopencv2opengl(rgb_int, calib.rgb_width, calib.rgb_height, calib.near, calib.far, rgb_KK); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n rgb_intrinsics converted to opengl"); printM(rgb_KK, 4, 4); // depth depth_int = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "depth_intrinsics"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n depth_intrinsics opencv (kinect_calibration.yml)"); printM(depth_int); calib.fx_d = (float)cvGetReal2D( depth_int, 0, 0 ); calib.fy_d = (float)cvGetReal2D( depth_int, 1, 1 ); calib.cx_d = (float)cvGetReal2D( depth_int, 0, 2 ); calib.cy_d = (float)cvGetReal2D( depth_int, 1, 2 ); CvMat* d_size = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "depth_size"); calib.depth_width = (int)cvGetReal2D( d_size, 0, 0 ); calib.depth_height = (int)cvGetReal2D( d_size, 0, 1 ); cvReleaseMat(&d_size); convertKKopencv2opengl(depth_int, calib.depth_width, calib.depth_height, calib.near, calib.far, depth_KK); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n depth_intrinsics converted to opengl"); printM(depth_KK, 4, 4); // depth/rgb RT rgb_R = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "R"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n rgb_R opencv (kinect_calibration.yml)"); printM(rgb_R); rgb_T = (CvMat*)cvLoad(kinect_calibration_filename_str, NULL, "T"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n rgb_T opencv (kinect_calibration.yml)"); printM(rgb_T); convertRTopencv2opengl(rgb_R, rgb_T, rgb_RT); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n rgb_RT converted to opengl"); printM(rgb_RT, 4, 4); // T_rgb = ofVec3f( // rgb_RT[12], rgb_RT[13], rgb_RT[14] ); calib.RT_rgb = ofMatrix4x4( rgb_RT[0], rgb_RT[1], rgb_RT[2], rgb_RT[12], rgb_RT[4], rgb_RT[5], rgb_RT[6], rgb_RT[13], rgb_RT[8], rgb_RT[9], rgb_RT[10], rgb_RT[14], 0., 0., 0., 1); // R_rgb.preMultTranslate(-T_rgb); // R_rgb = ofMatrix4x4::getTransposedOf(R_rgb); // proyector proj_int = (CvMat*)cvLoad(proj_calibration_filename_str, NULL, "proj_intrinsics"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n proj_intrinsics opencv (projector_calibration.yml)"); printM(proj_int); calib.fx_p = (float)cvGetReal2D( proj_int, 0, 0 ); calib.fy_p = (float)cvGetReal2D( proj_int, 1, 1 ); calib.cx_p = (float)cvGetReal2D( proj_int, 0, 2 ); calib.cy_p = (float)cvGetReal2D( proj_int, 1, 2 ); CvMat* p_size = (CvMat*)cvLoad(proj_calibration_filename_str, NULL, "proj_size"); calib.proj_width = (int)cvGetReal2D( p_size, 0, 0 ); calib.proj_height = (int)cvGetReal2D( p_size, 0, 1 ); cvReleaseMat(&p_size); convertKKopencv2opengl(proj_int, calib.proj_width, calib.proj_height, calib.near, calib.far, proj_KK); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n proj_intrinsics converted to opengl"); printM(proj_KK, 4, 4); proj_R = (CvMat*)cvLoad(proj_calibration_filename_str, NULL, "R"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n proj_R opencv (projector_calibration.yml)"); printM(proj_R); proj_T = (CvMat*)cvLoad(proj_calibration_filename_str, NULL, "T"); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n proj_T opencv (projector_calibration.yml)"); printM(proj_T); convertRTopencv2opengl(proj_R, proj_T, proj_RT); ofLog(OF_LOG_VERBOSE, "Camara Lucida \n proj_RT converted to opengl"); printM(proj_RT, 4, 4); }
void Calibration::device_config( string calib_path, string int_id, string size_id, string R_id, string T_id, OpticalDevice::Config& dev_config ) { CvMat* _int = (CvMat*)cvLoad( calib_path.c_str(), NULL, int_id.c_str() ); CvMat* _size = (CvMat*)cvLoad( calib_path.c_str(), NULL, size_id.c_str() ); CvMat* _R = (CvMat*)cvLoad( calib_path.c_str(), NULL, R_id.c_str() ); CvMat* _T = (CvMat*)cvLoad( calib_path.c_str(), NULL, T_id.c_str() ); int w = (int)cvGetReal2D( _size, 0, 0 ); int h = (int)cvGetReal2D( _size, 0, 1 ); float fx = (float)cvGetReal2D( _int, 0, 0 ); float fy = (float)cvGetReal2D( _int, 1, 1 ); float cx = (float)cvGetReal2D( _int, 0, 2 ); float cy = (float)cvGetReal2D( _int, 1, 2 ); // opencv: row-major // R x axis ofVec3f X = ofVec3f( (float)cvGetReal2D( _R, 0, 0 ), //xx (float)cvGetReal2D( _R, 1, 0 ), //xy (float)cvGetReal2D( _R, 2, 0 ) //xz ); // R y axis ofVec3f Y = ofVec3f( (float)cvGetReal2D( _R, 0, 1 ), //yx (float)cvGetReal2D( _R, 1, 1 ), //yy (float)cvGetReal2D( _R, 2, 1 ) //yz ); // R z axis ofVec3f Z = ofVec3f( (float)cvGetReal2D( _R, 0, 2 ), //zx (float)cvGetReal2D( _R, 1, 2 ), //zy (float)cvGetReal2D( _R, 2, 2 ) //zz ); // T ofVec3f T = ofVec3f( (float)cvGetReal2D( _T, 0, 0 ), //tx (float)cvGetReal2D( _T, 1, 0 ), //ty (float)cvGetReal2D( _T, 2, 0 ) //tz ); dev_config.size( w, h ); dev_config.intrinsics( cx, cy, fx, fy ); dev_config.extrinsics( X, Y, Z, T ); ofLog(OF_LOG_VERBOSE, "cml::Calibration"); ofLog(OF_LOG_VERBOSE, calib_path); ofLog(OF_LOG_VERBOSE, int_id); printM( _int ); //ofLog( OF_LOG_VERBOSE, "R" ); //printM( _R ); //ofLog( OF_LOG_VERBOSE, "T" ); //printM( _T ); ofLog(OF_LOG_VERBOSE,"RX:"+ofToString(X)); ofLog(OF_LOG_VERBOSE,"RY:"+ofToString(Y)); ofLog(OF_LOG_VERBOSE,"RZ:"+ofToString(Z)); ofLog(OF_LOG_VERBOSE,"T:"+ofToString(T)); cvReleaseMat( &_int ); cvReleaseMat( &_size ); cvReleaseMat( &_R ); cvReleaseMat( &_T ); };