int main(void){ int **R, **G, **B, **Y, **F, **L; int hist[256]; int boader; int label_num; R = (int **)IAllocImage(640,480); // 画像領域(赤)を確保 G = (int **)IAllocImage(640,480); // 画像領域(緑)を確保 B = (int **)IAllocImage(640,480); // 画像領域(青)を確保 Y = (int **)IAllocImage(640,480); // 画像領域(グレースケール)を確保 F = (int **)IAllocImage(640,480); // 画像領域(二値)を確保 L = (int **)IAllocImage(640,480); // 画像領域(ラベル付)を確保 GInit(640,480); // Windowの生成 ILoadPpmImage("abstmix.ppm",R,G,B); // ppmファイルの読み込み TranslateGrayScale(R,G,B,Y); // グレースケールに変換 MakeHistogram(Y,hist); // ヒストグラム作成 DisplayColorImage(Y,Y,Y); boader = Percentile(Y,hist,0.92); TranslateBoolScale(Y,F,boader); // パーセンタイル法で2値化 remove_noise(F,13); label_num=labeling(F,L); DisplayColorImage(F,F,F); printf("label_num=%d\n",label_num); printLabelingData(L,label_num); GWaitLoop(); // 終了処理 exit(EXIT_SUCCESS); }
int main(void){ int **R, **G, **B, **Y, **F; int hist[256]; double per; // パーセンタイル法におけるpの値 int boader; R = (int **)IAllocImage(640,480); // 画像領域(赤)を確保 G = (int **)IAllocImage(640,480); // 画像領域(緑)を確保 B = (int **)IAllocImage(640,480); // 画像領域(青)を確保 Y = (int **)IAllocImage(640,480); // 画像領域(グレースケール)を確保 F = (int **)IAllocImage(640,480); // 画像領域(二値)を確保 GInit(640,480); // Windowの生成 ILoadPpmImage("abstmix.ppm",R,G,B); // ppmファイルの読み込み TranslateGrayScale(R,G,B,Y); // グレースケールに変換 MakeHistogram(Y,hist); // ヒストグラム作成 DisplayColorImage(Y,Y,Y); printf("input per\n"); while(EOF!=scanf("%lf",&per)){ // パーセンタイル法で二値化 printf("per=%g,black=%g\n",per,IE*JE*per); boader = Percentile(Y,hist,per); printf("boader=%d\n",boader); TranslateBoolScale(Y,F,boader); remove_noise(F,0); DisplayColorImage(F,F,F); } GWaitLoop(); // 終了処理 exit(EXIT_SUCCESS); }
void loop() { Timer loop_t = Timer("TOTAL"); cv::Mat depth, obstacle, clear; cv_bridge::CvImagePtr img; { Timer setup_t = Timer("setup"); /* Grab a pair of images */ sensor_msgs::Image::ConstPtr img_msg; stereo_msgs::DisparityImage::ConstPtr disp_msg; get_images(img_msg, disp_msg); if (img_msg == NULL || disp_msg == NULL) { loop_t.disable(); setup_t.disable(); //ROS_INFO("No images"); return; } /* We don't want to waste time calculating the same image twice. */ unsigned int seq = disp_msg->image.header.seq; if (last_seq == seq && !last_msg) { ROS_INFO("Old message #%d", seq); loop_t.disable(); setup_t.disable(); last_msg = true; return; } last_seq = seq; last_msg = false; /* Display raw image */ img = cv_bridge::toCvCopy(img_msg, sensor_msgs::image_encodings::BGR8); /* Get disparity data */ cv_bridge::CvImagePtr disp = cv_bridge::toCvCopy(disp_msg->image, "32FC1"); float focal = disp_msg->f; float base = disp_msg->T; /* Generate depth image */ /* Why are these so inaccurate? Calibration issue? float min_depth = (focal * base) / disp_msg->min_disparity; float max_depth = (focal * base) / disp_msg->max_disparity; */ cv::Mat full_depth = (focal * base) / disp->image; /* Not be necessary if downscale = 1 */ cv::resize(full_depth, depth, cv::Size(IMG_WIDTH, IMG_HEIGHT)); /* Display value-scaled depth image */ #ifdef CV_OUTPUT cv::Mat scaled_depth = depth / RANGE_MAX; cv::imshow(DEPTH_WINDOW, scaled_depth); #endif /* Create empty obstacle map */ obstacle = cv::Mat::zeros(IMG_HEIGHT, IMG_WIDTH, CV_32F); clear = cv::Mat::zeros(IMG_HEIGHT, IMG_WIDTH, CV_32F); } float pct_good; /* Find and display obstacles */ { Timer obs_t = Timer("find_obstacles"); pct_good = find_obstacles(depth, obstacle, RANGE_MIN, 100.0); } #ifdef CV_OUTPUT cv::Mat scaled_obs = obstacle / RANGE_MAX; cv::imshow(OBS_WINDOW, scaled_obs); #endif std::vector<Slice> slices; std::vector<RectList> slice_bboxes; { Timer slice_t = Timer("calc slicing"); /* Set up slices */ { Timer init_t = Timer("init", 1); init_slices(slices); } { Timer fill_t = Timer("fill", 1); fill_slices(obstacle, slices, RANGE_MAX); } { Timer noise_t = Timer("noise", 1); for (int i = 0; i < slices.size(); i++) { remove_noise(slices[i].mat); } } { Timer bbox_t = Timer("bbox", 1); /* Calculate bounding box on each slice */ for (int i = 0; i < slices.size(); i++) { slice_bboxes.push_back(calc_bboxes(slices[i].mat)); } } } cv::Mat boxes_image, final_image; { Timer disp_t = Timer("disp slicing"); /* Display bounding boxes on image */ boxes_image = img->image.clone(); /* Convert box image to HSV */ cv::cvtColor(boxes_image, boxes_image, cv::COLOR_BGR2HSV); /* Loop backwards-- farthest first, panter's algorithm */ for (int i = slice_bboxes.size()-1; i >= 0; i--) { /* Calculate hue */ int hue = (int)(((float)i)/((float)slice_bboxes.size())*120.0); cv::Scalar color = cv::Scalar(hue, 255, 255); for (int j = 0; j < slice_bboxes[i].size(); j++) { //TODO: Iterators??? /* Get / resize boxes */ cv::Rect bbox = slice_bboxes[i][j]; bbox.x *= DOWNSCALE; bbox.y *= DOWNSCALE; bbox.width *= DOWNSCALE; bbox.height *= DOWNSCALE; /* Draw boxes */ cv::rectangle(boxes_image, bbox, color, -1); } } /* Convert back to RGB */ cv::cvtColor(boxes_image, boxes_image, cv::COLOR_HSV2BGR); /* Combine with image */ cv::addWeighted(boxes_image, 0.3, img->image, 0.7, 0.0, final_image); } /* Generate top-down image */ cv::Mat top; top = cv::Mat::zeros(TOP_SIZE, TOP_SIZE, CV_8UC1); Grid grid = Grid(GRID_WIDTH, GRID_HEIGHT, RANGE_MAX, RANGE_MAX); { Timer top_t = Timer("topdown"); /* Init top-down image */ calc_topdown_grid(grid, slices, slice_bboxes, RANGE_MAX); publish_grid(grid, pct_good); draw_grid(grid, top); calc_topdown(top, slices, slice_bboxes, RANGE_MAX); } #ifdef CV_OUTPUT cv::imshow(TOP_WINDOW, top); cv::imshow(IMAGE_WINDOW, final_image); #endif #if defined(__SLICE_DEBUG) && defined(CV_OUTPUT) for (int i = 0; i < NUM_SLICES; i++) { std::string s = "a"; s[0] = 'a'+i; cv::imshow(s, slices[i]); } #endif }
// Main function int main (void) { // Local variable definations emxArray_uint8_T *xaxis; emxArray_uint8_T *yaxis; emxArray_uint8_T *norm_xaxis_filt; emxArray_uint8_T *norm_yaxis_filt; uint16_T count; uint8_T xaxis2,yaxis2; long j = 0; int again = 1; char letter; char letterstr[10]; int i=0; letterstr[i] = '\0'; // Variable Initialisation for(j=0;j<MAX_VALUE;j++) { xdata[j] = 0; ydata[j] = 0; } // Function Initialisation PINSEL2 &= ~((1<<2)|(1<<3)); GLCD_Initalize(); //Initialize the LCD Init_UART(); InitADC(); // Welcome message GLCD_ClearScreen(); GLCD_GoTo(10,4); GLCD_WriteString("Intelligent e-book"); // for(j=0;j<999999;j++); delay_ms(2000); // Calibration //Left bottom GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Calibration"); GLCD_GoTo(10,4); GLCD_WriteString("Touch the point"); GLCD_GoTo(0,7); GLCD_WriteString("o"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); for(j=0;j<25;j++) capture(); x1 = xaxis1; y1 = yaxis1; GLCD_GoTo(10,5); GLCD_WriteString("Stored"); delay_ms(1000); //Right top GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Calibration"); GLCD_GoTo(10,4); GLCD_WriteString("Touch the point"); GLCD_GoTo(120,0); GLCD_WriteString("o"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); for(j=0;j<25;j++) capture(); x2 = xaxis1; y2 = yaxis1; GLCD_GoTo(10,5); GLCD_WriteString("Stored"); delay_ms(1000); while(again==1) { again = 0; // Capturing xaxis and yaxis GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(12,4); GLCD_WriteString("Waiting for input"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); xyelem = 0; count = 0; GLCD_ClearScreen(); GLCD_GoTo(0,0); // Eliminate first 25 samples for(j=0;j<25;j++) capture(); while(count!=250) { capture(); if(xaxis1!=0 && yaxis1!=0 && count==0) { // xaxis2 = (uint8_T)(((xaxis1-80)*255)/730); // yaxis2 = (uint8_T)(((yaxis1-100)*255)/650); xaxis2 = (uint8_T)(((xaxis1-x1)*255)/(x2-x1)); yaxis2 = (uint8_T)(((yaxis1-y1)*255)/(y2-y1)); count = 0; xdata[xyelem] = xaxis2; ydata[xyelem] = yaxis2; xyelem = xyelem + 1; GLCD_SetPixel(xaxis2/2,255-(yaxis2/4),1); if(xyelem>MAX_VALUE - 1) { GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(10,4); GLCD_WriteString("Overflow!!!"); while(1); } } else if(xaxis1!=0 && yaxis1!=0) { xyelem = xyelem - 2; // Eliminate first 25 samples for(j=0;j<25;j++) capture(); count = 0; } else { count = count + 1; } // delay(1000); } GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(0,1); GLCD_WriteString(letterstr); //GLCD_GoTo(10,4); //GLCD_WriteString("Scanning ended"); //delay_ms(500); // Transmitting data to PC // transmit(); // Remove noise remove_noise(); // Allocating space for pointers xaxis = emxCreateWrapper_uint8_T(xdata,1,xyelem); //xdata1 yaxis = emxCreateWrapper_uint8_T(ydata,1,xyelem); //ydata1 emxInit_uint8_T(&norm_xaxis_filt, 2); emxInit_uint8_T(&norm_yaxis_filt, 2); /* GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(0,2); GLCD_WriteString("Step1"); GLCD_GoTo(37,2); GLCD_WriteString("In"); */ // for(j=0;j<999999;j++); step1(xaxis, yaxis, norm_xaxis_filt, norm_yaxis_filt); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,2); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); emxDestroyArray_uint8_T(xaxis); emxDestroyArray_uint8_T(yaxis); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,3); // GLCD_WriteString("Step2"); // GLCD_GoTo(37,3); // GLCD_WriteString("In"); // for(j=0;j<999999;j++); // char_bin is stored in column first fashion... each column vector are concatenated step2(norm_xaxis_filt, norm_yaxis_filt, char_bin); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,3); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); emxFree_uint8_T(&norm_xaxis_filt); emxFree_uint8_T(&norm_yaxis_filt); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,4); // GLCD_WriteString("Step3"); // GLCD_GoTo(37,4); // GLCD_WriteString("In"); // for(j=0;j<999999;j++); for(j=0;j<10;j++) char_vec[j] = 1; step3(char_bin, char_vec); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,4); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); for(j=0;j<26;j++) char_vec1[j] = char_vec[j]; // Feeding char_vec to trained neural network char_recog_nn(char_vec1,Y); letter = character(); letterstr[i] = letter; letterstr[i+1] = '\0'; // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,6); // GLCD_WriteString("Letter is: "); GLCD_GoTo(0,1); GLCD_WriteString(letterstr); GLCD_GoTo(0,7); GLCD_WriteString("Continue"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); again = 1; i = i + 1; /* GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(20,4); GLCD_WriteString("Restarting."); delay_ms(200); GLCD_WriteString("."); delay_ms(200); GLCD_WriteString("."); delay_ms(200); GLCD_WriteString("."); */ delay_ms(400); } while(1); }