Rose-Hulman Robotics Team

Changeset 714 for trunk/software

Show
Ignore:
Timestamp:
03/03/10 02:42:10 (2 years ago)
Author:
mosttw
Message:

Blurring of the sobelized image

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/vision/_processing.c

    r713 r714  
    8282 
    8383        Py_BEGIN_ALLOW_THREADS 
     84                // Parameters of the operation (should probably be attributes). 
     85                int sobel_aperture = 5; 
     86                int blur_aperture = 3; 
     87 
     88                // Calculate the "working" image size 
     89                int scale_factor = 4; 
     90                int working_width  = input->width  / scale_factor; 
     91                int working_height = input->height / scale_factor; 
     92 
    8493                // All these buffers should probably be moved to attributes of the VisionProcessor 
    8594                // so that they needn't be reallocated all the time. 
    86                 int sobel_aperture = 5; // 3, 5, or 7 
    87                 //int scale_factor = 2; 
    88                 //int processing_width  = input->width  / scale_factor; 
    89                 //int processing_height = input->height / scale_factor; 
     95                IplImage *hsv_full; 
    9096                IplImage *hsv; 
    91                 IplImage *v; 
     97                IplImage *v_full; 
     98                CvMat *sobel_full; 
    9299                CvMat *sobel; 
    93                 IplImage *sobel_im; 
    94  
    95                 hsv      = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3); 
    96                 v        = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 1); 
    97                 sobel    = cvCreateMat(input->height, input->width, CV_32FC1); 
    98                 sobel_im = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 1); 
    99                 output   = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3); 
    100  
    101                 cvCvtColor(input, hsv, CV_BGR2HSV); 
    102                 cvSplit(hsv, NULL, NULL, v, NULL); 
    103                 cvSobel(v, sobel, 1, 1, sobel_aperture); 
    104                 cvConvertScale(sobel, sobel_im, 8.0, 0); 
    105                 cvCvtColor(sobel_im, output, CV_GRAY2BGR); 
     100                IplImage *texture; 
     101 
     102                hsv_full   = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3); 
     103                hsv        = cvCreateImage(cvSize(working_width, working_height), IPL_DEPTH_8U, 3); 
     104                v_full     = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 1); 
     105                sobel_full = cvCreateMat(input->height, input->width, CV_32FC1); 
     106                sobel      = cvCreateMat(working_height, working_width, CV_32FC1); 
     107                texture    = cvCreateImage(cvSize(working_width, working_height), IPL_DEPTH_8U, 1); 
     108                output     = cvCreateImage(cvSize(working_width, working_height), IPL_DEPTH_8U, 3); 
     109 
     110                // Colorspace conversion and scaling 
     111                cvCvtColor(input, hsv_full, CV_BGR2HSV); 
     112                cvSplit(hsv_full, NULL, NULL, v_full, NULL); 
     113                cvResize(hsv_full, hsv, CV_INTER_AREA); 
     114 
     115                // Calculate "texture" channel 
     116                cvSobel(v_full, sobel_full, 1, 1, sobel_aperture); 
     117                cvResize(sobel_full, sobel, CV_INTER_AREA); 
     118                cvConvertScale(sobel, texture, 8.0, 0); 
     119                cvSmooth(texture, texture, CV_BLUR, blur_aperture, 0, 0, 0); 
     120 
     121                // Create output image 
     122                cvCvtColor(texture, output, CV_GRAY2BGR); 
    106123         
     124                cvReleaseImage(&hsv_full); 
    107125                cvReleaseImage(&hsv); 
    108                 cvReleaseImage(&v); 
     126                cvReleaseImage(&v_full); 
     127                cvReleaseMat(&sobel_full); 
    109128                cvReleaseMat(&sobel); 
    110                 cvReleaseImage(&sobel_im); 
     129                cvReleaseImage(&texture); 
    111130        Py_END_ALLOW_THREADS 
    112131