[問題] opencv加上openmp的問題
看板C_and_CPP (C/C++)作者benbchung (距離...是妳經過我的時候)時間15年前 (2011/01/17 13:22)推噓1(1推 0噓 3→)留言4則, 2人參與討論串1/1
小弟使用opencv抓取影像的RGB顏色做HSV轉換再從HSV轉回RGB秀出影像,當我想另外附加
openmp做多核運算時.轉換結果跑出來的影像卻會出現雜點.
如果沒有使用OPENMP的話,卻不會有這種狀況出現,轉換的影像都很正常.
我不太了解這是怎麼回事?
我使用的介面是VC2008,下面是我轉換的函式,想請各位前輩指教一下是哪裡可能有錯!
void rgb2hsi(IplImage *Image1,IplImage *HSVImage1)
{
uchar Blue,Green,Red;
double sqrtrgrbgb=1,ragab;;
for(int j=0;j<Image1->height;j++)
{
#pragma omp parallel for
for(int i=0;i<Image1->widthStep;i=i+3)
{
Blue=Image1->imageData[j*Image1->widthStep+i];
Green=Image1->imageData[j*Image1->widthStep+i+1];
Red=Image1->imageData[j*Image1->widthStep+i+2];
double I,S,H,sita;
double r,g,b;
r=Red;
g=Green;
b=Blue;
sqrtrgrbgb=sqrt( (r-g)*(r-g)+(r-b)*(g-b) );
if(sqrtrgrbgb!=0)
sita= acos( 0.5*(2*r-g-b) / sqrtrgrbgb )*180/PI;
else
sita= acos( 0.5*(2*r-g-b) / 0.01 )*180/PI;
if(b<=g)
H=sita;
else if(b>g)
H=360-sita;
int minrgb;
if(r<=g&&r<=b)
minrgb=r;
else if(g<=r&&g<=b)
minrgb=g;
else
minrgb=b;
ragab=r+g+b;
if(ragab!=0)
S=1-3*minrgb/ragab;
else
S=1-3*minrgb/0.01;
I=(r+g+b)/3;
if(H<120&&H>=0)
{
b=I*(1-S);
r=I*( 1+( S*cos(H*PI/180 ) /(cos( (60-H) *PI/180 )
) ) );
g=3*I-(r+b);
}
else if(H<240&&H>=120)
{
H=H-120;
r=I*(1-S);
g=I*( 1+( S*cos(H*PI/180 ) /(cos( (60-H) *PI/180 )
) ) );
b=3*I-(r+g);
}
else
{
H=H-240;
g=I*(1-S);
b=I*( 1+( S*cos(H*PI/180 ) /(cos( (60-H) *PI/180 )
) ) );
r=3*I-(b+g);
}
Image1->imageData[j*Image1->widthStep+i]=b;//b
Image1->imageData[j*Image1->widthStep+i+1]=g;//g
Image1->imageData[j*Image1->widthStep+i+2]=r;//r
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.124.201.62
推
01/17 13:24, , 1F
01/17 13:24, 1F
→
01/17 13:25, , 2F
01/17 13:25, 2F
→
01/17 13:26, , 3F
01/17 13:26, 3F
→
01/17 13:36, , 4F
01/17 13:36, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章