opencv IPL_DEPTH_32F的图像如何显示??
voidcalculateGradient(constIplImage*frame1,int&vfps){IplImage*frameGray=cvCreateImage...
void calculateGradient(const IplImage *frame1, int &vfps)
{
IplImage *frameGray = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_8U, 1);
IplImage *gradient = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_32F, 1);
IplImage *gradient1 = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_8U, 1);
cvCvtColor(frame1, frameGray, CV_RGB2GRAY);
//IplImage *gradientX, *gradientY;
IplImage *gradientX = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_16S, 1);
IplImage *gradientY = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_16S, 1);
cvSobel(frameGray,gradientY,0,1,3);
cvSobel(frameGray,gradientX,1,0,3);
for (int j = 0; j < gradientX->height; j++) {
float *ptrX = (float *) (gradientX->imageData + j * gradientX->widthStep);
float *ptrY = (float *) (gradientY->imageData + j * gradientY->widthStep);
float *ptr = (float *) (gradient->imageData + j * gradient->widthStep);
for (int i = 0; i < gradient->width; i++) {
ptr[i] = cvRound (sqrt(ptrX[i] * ptrX[i] + ptrY[i] * ptr[i]));
}
}
cvConvertScale(gradient, gradient1, 0.25, 0.0);
cvShowImage("gradient", gradient1);
cvWaitKey(vfps);
cvReleaseImage(&gradient);
cvReleaseImage(&gradient1);
cvReleaseImage(&frameGray);
cvReleaseImage(&gradientX);
cvReleaseImage(&gradientY);
} 展开
{
IplImage *frameGray = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_8U, 1);
IplImage *gradient = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_32F, 1);
IplImage *gradient1 = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_8U, 1);
cvCvtColor(frame1, frameGray, CV_RGB2GRAY);
//IplImage *gradientX, *gradientY;
IplImage *gradientX = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_16S, 1);
IplImage *gradientY = cvCreateImage(cvGetSize(frame1), IPL_DEPTH_16S, 1);
cvSobel(frameGray,gradientY,0,1,3);
cvSobel(frameGray,gradientX,1,0,3);
for (int j = 0; j < gradientX->height; j++) {
float *ptrX = (float *) (gradientX->imageData + j * gradientX->widthStep);
float *ptrY = (float *) (gradientY->imageData + j * gradientY->widthStep);
float *ptr = (float *) (gradient->imageData + j * gradient->widthStep);
for (int i = 0; i < gradient->width; i++) {
ptr[i] = cvRound (sqrt(ptrX[i] * ptrX[i] + ptrY[i] * ptr[i]));
}
}
cvConvertScale(gradient, gradient1, 0.25, 0.0);
cvShowImage("gradient", gradient1);
cvWaitKey(vfps);
cvReleaseImage(&gradient);
cvReleaseImage(&gradient1);
cvReleaseImage(&frameGray);
cvReleaseImage(&gradientX);
cvReleaseImage(&gradientY);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询