techsharad / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Issue with cvCvtColor #269

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I use cvFindContours to find numbers segment in a number plate, it works great. 
After that, I want to convert it to grayscale (for OCR), I use cvCvtColor but 
it makes me so confused.

SOME IMAGES ARE ATTACHED, see it then you can understand my issue.

It's so strange, some work fine, but some not. Anyone can help me?

Oh, this is my code:

CvSeq contours = new CvSeq();
                IplImage contour_img = cvCreateImage( cvGetSize( plateImageGrey ), IPL_DEPTH_8U, 1);
                cvZero( contour_img );
                CvMemStorage storage = CvMemStorage.create();                   
                cvFindContours( plateImageGrey, storage, contours, Loader.sizeof(CvContour.class), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );              
                while(contours != null)
                {
                    if(CV_IS_SEQ_CONTOUR(contours))
                    {
                        cvDrawContours( contour_img, contours, cvScalarAll(255), cvScalarAll(255), CV_C, CV_C, CV_C );
                        CvRect  boundingRect = cvBoundingRect(contours,1); 
                        if(((boundingRect.height()/boundingRect.width()) >=  2.0) && ((boundingRect.height()/boundingRect.width()) <=  3.0) && (area >= 1000))
                        {                           
                            CvRect cr = new CvRect(boundingRect.x() - 5 , boundingRect.y() - 5, boundingRect.width() + 10, boundingRect.height() + 10);                             
                            cvSetImageROI(plateImage, cr);                      
                            IplImage charImage = cvCreateImage(cvGetSize(plateImage), plateImage.depth(), plateImage.nChannels());
                            cvCopy(plateImage, charImage);
                            cvResetImageROI(plateImage);

                            IplImage charImageGrey = cvCreateImage( cvGetSize( charImage ), IPL_DEPTH_8U, 1);
                            cvCvtColor( charImage, charImageGrey, CV_BGRA2GRAY);

                            Bitmap charImageBitmap = Bitmap.createBitmap(charImageGrey.width(), charImageGrey.height(), Bitmap.Config.ALPHA_8);
                            charImageBitmap.copyPixelsFromBuffer(charImageGrey.getByteBuffer());
                            charImageBitmap = charImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
                        }
                    }
                    contours = contours.h_next();           
                }
Thanks in advance!!!

Original issue reported on code.google.com by don.ngu...@hazuu.com on 6 Jan 2013 at 12:34

Attachments:

GoogleCodeExporter commented 9 years ago
Bitmap.copyPixelsFromBuffer() only supports contiguous memory regions. Can you 
try to use this line instead when creating your `charImage`?
IplImage charImage = cvCreateImage(cr, plateImage.depth(), 
plateImage.nChannels());

Original comment by samuel.a...@gmail.com on 13 Jan 2013 at 3:34

GoogleCodeExporter commented 9 years ago
Given the lack of feedback, I assume that you were able to get this working. 
Next time, please post your questions on the mailing list if possible, thank you

Original comment by samuel.a...@gmail.com on 5 Mar 2013 at 11:01