[[Template core/front/global/updateWarning is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]]
لدي كود كلاس جاهز اود استخدامه في مشروع على بيئة 2008 ولكن لم اعرف ان استحدث ملف كلاس جديد لاضافة الكود له حيث ان الكود الذي حصلت عليه لا يوجد فيه classname.h ارجو من الاخوة المساعدة لضيق الوقت
هذا كود الكلاس الذي اود اضافته
//CLASS DYNAMIC MATRIXclass Mat {public: Mat(int ,int ); ~Mat(); double get(int ,int ); void set (int ,int , double ); private: int num_row; int num_col; double * val;};Mat::Mat(int nrow, int ncol){ num_row=nrow; num_col=ncol; val =new double [num_row * num_col]; return;}double Mat::get(int row, int col){ return val[row * this->num_col + col];}void Mat::set(int row, int col, double v){ val[row* this->num_col +col]=v; return; }Mat::~Mat(){ delete [] val;}/////////////////////////////Hough1 transform =============== double pmin; double pmax; double tmin; double tmax;Bitmap ^ Hough(Bitmap ^ im1){ int w=im1->Width,h=im1->Height; int thetaMx=180; int pMx=181;Mat * EdgeMag=new Mat(h,w);Mat * EdgePhase=new Mat(h,w);//==================sobel int filtersize=3; int sobely[3][3]= {-1,-2,-1, 0 , 0, 0, 1 , 2, 1}; int sobelx[3][3]= {-1, 0, 1, -2, 0, 2, -1, 0, 1}; double Rx,Ry; int x,y,i,j; for (x=0;x<w ;x++) for(y=0;y<h ;y++){ Rx=Ry=0.0; for ( i=-filtersize/2;i<=filtersize/2;i++) for ( j=-filtersize/2;j<=filtersize/2;j++){ if (!(x+i<0 || x+i>=w || y+j<0 || y+j>=h)){ Color c=im1->GetPixel(x+i,y+j); int r= (c.R+c.G+c.B)/3; Ry+=r*sobely[i+filtersize/2][j+filtersize/2]; Rx+=r*sobelx[i+filtersize/2][j+filtersize/2]; } else { Color cc=im1->GetPixel(x ,y ); int r= (cc.R+cc.G+cc.B)/3; Ry+=r*sobely[i+filtersize/2][j+filtersize/2]; Rx+=r*sobelx[i+filtersize/2][j+filtersize/2]; } } int R=Math::Abs(Rx) + Math::Abs(Ry) ; if (R>255) R=255; EdgeMag->set(y,x,R); EdgePhase->set(y,x,Math::Atan2(Ry,Rx)); }// for //=================end sobel//initilize output image for sin drawBitmap ^outSinCos=gcnew Bitmap(thetaMx,pMx);for (int x=0;x<thetaMx ;x++) for(int y=0;y<pMx ;y++){ outSinCos->SetPixel(x,y,Color::Black); }//read from magnitude and add to accumilator image outsincos pmin=9999999999.0; pmax=-9999999999.0; double p,Pi=Math::PI; //scale p for (x=0;x<w ;x++) for(y=0;y<h ;y++){ int r=EdgeMag->get(y,x); if (r>254){ for (int i=0;i<thetaMx;i++){ p=x*Math::Cos(i*Pi/180.0)+y*Math::Sin(i*Pi/180.0); if (p<pmin) pmin=p; if (p>pmax) pmax=p; } } } //accumilate for (x=0;x<w ;x++) for(y=0;y<h ;y++){ int r=EdgeMag->get(y,x); if (r>254){ for (int i=0;i<thetaMx;i++){ p=x*Math::Cos(i*Pi/180.0)+y*Math::Sin(i*Pi/180.0); p=180.0*(p-pmin)/(pmax-pmin); int r=outSinCos->GetPixel(i,p).R+1; if (r>255) r=255; outSinCos->SetPixel(i,p,Color::FromArgb(r,r,r)); } } }return outSinCos; }////////////////////////////////Hough2 transform =============== int thetaMx; int pMx;Bitmap ^ Hough2(Bitmap ^ im1){ int w=im1->Width,h=im1->Height; thetaMx=180; pMx=181;Mat * EdgeMag=new Mat(h,w);Mat * EdgePhase=new Mat(h,w);//==================sobel int filtersize=3; int sobely[3][3]= {-1,-2,-1, 0 , 0, 0, 1 , 2, 1}; int sobelx[3][3]= {-1, 0, 1, -2, 0, 2, -1, 0, 1}; double Rx,Ry; int x,y,i,j; for (x=0;x<w ;x++) for(y=0;y<h ;y++){ Rx=Ry=0.0; for ( i=-filtersize/2;i<=filtersize/2;i++) for ( j=-filtersize/2;j<=filtersize/2;j++){ if (!(x+i<0 || x+i>=w || y+j<0 || y+j>=h)){ Color c=im1->GetPixel(x+i,y+j); int r= (c.R+c.G+c.B)/3; Ry+=r*sobely[i+filtersize/2][j+filtersize/2]; Rx+=r*sobelx[i+filtersize/2][j+filtersize/2]; } else { Color cc=im1->GetPixel(x ,y ); int r= (cc.R+cc.G+cc.B)/3; Ry+=r*sobely[i+filtersize/2][j+filtersize/2]; Rx+=r*sobelx[i+filtersize/2][j+filtersize/2]; } } int R=Math::Abs(Rx) + Math::Abs(Ry) ; if (R>255) R=255; EdgeMag->set(y,x,R); EdgePhase->set(y,x,Math::Atan2(Ry,Rx)); }// for //=================end sobel//initilize output image for sin drawBitmap ^outSinCos=gcnew Bitmap(thetaMx,pMx);for (int x=0;x<thetaMx ;x++) for(int y=0;y<pMx ;y++){ outSinCos->SetPixel(x,y,Color::Black); }//read from magnitude and add to accumilator image outsincos pmin=9999999999.0; pmax=-9999999999.0; tmin=9999999999.0; tmax=-9999999999.0; double p,Pi=Math::PI; //scale p for (x=0;x<w ;x++) for(y=0;y<h ;y++){ int r=EdgeMag->get(y,x); if (r>254){ double t=EdgePhase->get(y,x); p=x*Math::Cos(t)+y*Math::Sin(t); if (p<pmin) pmin=p; if (p>pmax) pmax=p; if (t<tmin) tmin=t; if (t>tmax) tmax=t; } } //accumilate for (x=0;x<w ;x++) for(y=0;y<h ;y++){ int r=EdgeMag->get(y,x); if (r>254){ double t=EdgePhase->get(y,x); p=x*Math::Cos(t)+y*Math::Sin(t); t=(thetaMx-1)*(t-tmin)/(tmax-tmin); p=180.0*(p-pmin)/(pmax-pmin); int r=outSinCos->GetPixel(t,p).R+1; if (r>255) r=255; outSinCos->SetPixel(t,p,Color::FromArgb(r,r,r)); } }return outSinCos; }Bitmap ^ line(Bitmap ^ im1){ Image^ image =im1; Graphics ^gr = Graphics::FromImage(image); Pen ^ p1=gcnew Pen(Color::Blue); int w=im1->Width;int h=im1->Height; gr->DrawLine(p1,0,0,w-1,h-1); im1=dynamic_cast<Bitmap^>(image); return im1;}Bitmap ^ HoughLine(Bitmap ^ im1){ Image^ image =im1; Graphics ^gr = Graphics::FromImage(image); Pen ^ p1=gcnew Pen(Color::Blue); int w=im1->Width;int h=im1->Height; Bitmap ^ im2=Hough(im1); thetaMx=180; pMx=181;double Pi=Math::PI; int t,r; for (t=0;t<thetaMx ;t++) for(r=0;r<pMx ;r++){ Color c=im2->GetPixel(t,r); if (c.R>254){ double cos_t = Math::Cos(t*Pi/180.0), sin_t = Math::Sin(t*Pi/180.0); double rho=pmin+r*(pmax-pmin)/180.0; double x0 = rho*cos_t, y0 = rho*sin_t; double alpha = 1000; Point pt1( Math::Round(x0 + alpha*(-sin_t)), Math::Round(y0 + alpha*cos_t) ); Point pt2( Math::Round(x0 - alpha*(-sin_t)), Math::Round(y0 - alpha*cos_t) ); gr->DrawLine(p1,pt1,pt2); } } im1=dynamic_cast<Bitmap^>(image); return im1;}Bitmap ^ HoughLine2(Bitmap ^ im1,int threshold){ Image^ image =im1; Graphics ^gr = Graphics::FromImage(image); Pen ^ p1=gcnew Pen(Color::Blue); int w=im1->Width;int h=im1->Height; Bitmap ^ im2=Hough2(im1); thetaMx=180; pMx=181;double Pi=Math::PI; int t,r; for (t=0;t<thetaMx ;t++) for(r=0;r<pMx ;r++){ Color c=im2->GetPixel(t,r); if (c.R>threshold){ double rho=pmin+r*(pmax-pmin)/180.0; double theta=tmin+t*(tmax-tmin)/180.0; double cos_t = Math::Cos(theta), sin_t = Math::Sin(theta); double x0 = rho*cos_t, y0 = rho*sin_t; double alpha = 1000; Point pt1( Math::Round(x0 + alpha*(-sin_t)), Math::Round(y0 + alpha*cos_t) ); Point pt2( Math::Round(x0 - alpha*(-sin_t)), Math::Round(y0 - alpha*cos_t) ); gr->DrawLine(p1,pt1,pt2); } } im1=dynamic_cast<Bitmap^>(image); return im1;}
معلوماتي بسيطه في C++ اعتقد انه لازم استحدث كلاس باسم Mat.cpp واضافة الكود لكن كيف استدعيه وهل لازم استخدم header file اله وكيف اعمله
تم النشر منذ
بسم الله الرحمن الرحيم
لدي كود كلاس جاهز اود استخدامه في مشروع على بيئة 2008 ولكن لم اعرف ان استحدث ملف كلاس جديد لاضافة الكود له حيث ان الكود الذي حصلت عليه لا يوجد فيه classname.h ارجو من الاخوة المساعدة لضيق الوقت
هذا كود الكلاس الذي اود اضافته
معلوماتي بسيطه في C++ اعتقد انه لازم استحدث كلاس باسم Mat.cpp واضافة الكود لكن كيف استدعيه وهل لازم استخدم header file اله وكيف اعمله
شارك هذا الرد
رابط المشاركة
شارك الرد من خلال المواقع ادناه