前端之家收集整理的这篇文章主要介绍了
向量乘积,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//运行参数:girl.jpg
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"ml.lib")
#pragma comment(lib,"cvaux.lib")
#pragma comment(lib,"cvcam.lib")
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
inline void cvDoubleMatPrint( const CvMat* mat );
int main( int argc,char** argv )
{
IplImage* pImg; //声明IplImage指针
if( argc == 2 && (pImg = cvLoadImage( argv[1],CV_LOAD_IMAGE_UNCHANGED)) != 0 )
{
//*
double va[] = {1,2,3};
double vb[] = {0,1};
double vc[3];
CvMat Va=cvMat(3,1,CV_64FC1,va);
CvMat Vb=cvMat(3,vb);
CvMat Vc=cvMat(3,vc);
double res=cvDotProduct(&Va,&Vb); // 向量点乘: Va . Vb -> res
cvCrossProduct(&Va,&Vb,&Vc); // 向量叉乘: Va x Vb -> Vc
//注意在进行叉乘运算时,Va,Vb,Vc 必须是仅有3个元素的向量.
//*/
cvDoubleMatPrint(&Va);
cvDoubleMatPrint(&Vb);
cvDoubleMatPrint(&Vc);
printf("res=%lf\n",res);
cvNamedWindow( "Image",1 ); // 创建窗口
cvShowImage( "Image",pImg ); // 显示图像
cvWaitKey(0); // 等待按键
cvDestroyWindow( "Image" ); // 销毁窗口
cvReleaseImage( &pImg ); // 释放图像
return 0;
}
return -1;
}
inline void cvDoubleMatPrint( const CvMat* mat )
{
int i,j;
for( i = 0; i < mat->rows; i++ )
{
for( j = 0; j < mat->cols; j++ )
{
printf( "%lf ",cvmGet( mat,i,j ) );
}
printf( "\n" );
}
}
原文链接:https://www.f2er.com/vb/260058.html