CVTColor(JavaCV&x2B;OpenCV)出现问题!

CVTColor(JavaCV&x2B;OpenCV)出现问题!,opencv,javacv,Opencv,Javacv,我使用cvFindContours查找车牌中的数字段,效果非常好。之后,我想将其转换为灰度(用于OCR),我使用cvtColor,但这让我很困惑 车牌图像: 我得到的一些数字图像(在cvtcolor之后): 这太奇怪了,有些很好,但有些不行。有人能帮我吗 哦,这是我的代码: CvSeq contours = new CvSeq(); IplImage contour_img = cvCreateImage( cvGetSize( plateImageG

我使用
cvFindContours
查找车牌中的数字段,效果非常好。之后,我想将其转换为灰度(用于OCR),我使用
cvtColor
,但这让我很困惑

车牌图像:

我得到的一些数字图像(在
cvtcolor
之后):

这太奇怪了,有些很好,但有些不行。有人能帮我吗

哦,这是我的代码:

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();           
                }
CvSeq等高线=新的CvSeq();
IplImage CONTOURE_img=cvCreateImage(cvGetSize(PlateImageGray),IPL_DEPTH_8U,1);
cvZero(轮廓图);
CvMemStorage=CvMemStorage.create();
cvFindContours(平板图像灰色、存储、轮廓、装载机尺寸(CvContour.class)、CV_RETR_列表、CV_链近似_简单);
while(等高线!=null)
{
if(等高线等高线等高线)
{
cvdraw等高线(等高线、等高线、cvScalarAll(255)、cvScalarAll(255)、CV_C、CV_C、CV_C);
CvRect-boundingRect=cvBoundingRect(等高线,1);
如果(((boundingRect.height()/boundingRect.width())>=2.0)和(((boundingRect.height()/boundingRect.width())=1000))
{                           
CvRect cr=新CvRect(boundingRect.x()-5,boundingRect.y()-5,boundingRect.width()+10,boundingRect.height()+10);
cvSetImageROI(平板图像,cr);
IplImage charImage=cvCreateImage(cvGetSize(plateImage),plateImage.depth(),plateImage.nChannels());
cvCopy(plateImage、charImage);
cvResetImageROI(plateImage);
IplImage CHARIMAGEREY=cvCreateImage(cvGetSize(charImage),IPL_DEPTH_8U,1);
CVT颜色(charImage、CharimageGray、CV_BGRA2GRAY);
位图charImageBitmap=Bitmap.createBitmap(charImageGrey.width()、charImageGrey.height()、Bitmap.Config.ALPHA_8);
charImageBitmap.copyPixelsFromBuffer(charImageGrey.getByteBuffer());
charImageBitmap=charImageBitmap.copy(Bitmap.Config.ARGB_8888,true);
}
}
轮廓=轮廓。h_next();
}

提前感谢

cvtcolor
之前尝试显示
charImage
。他们没事吧?我试过了,他们没事!这就是为什么我认为这是CVTColor的问题!!可能是。这种图像损坏通常是宽度步长估计失败的结果。尝试将其转换为3通道图像。同时检查
plateImage
的深度。每个通道的宽度应该是8u。我猜看起来很好的图像的宽度是4的倍数。