News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Need Help looking my mistake on OpenCV

Started by Farabi, April 30, 2009, 11:32:13 AM

Previous topic - Next topic

Farabi

Dont know what is wrong with my code, I simply translate it from Intel OpenCV. The purpose for this function is to track an object based on the color spesified by the user.
Here is my code:
Quote
ObjectTrack2 proc uses esi edi cvArrImage:dword,DC:dword,lpRect:dword
   LOCAL img,hsv,hue,_mask,backproject,hist,histimg:dword
   LOCAL p:POINT
   LOCAL r:RECT
   LOCAL ctc:cvTermCriteria
   LOCAL track_comp:CvConnectedComp
   LOCAL data:CvBox2D
   LOCAL buff[256]:dword
   LOCAL tmp:qword
   LOCAL tmp2:dword
   LOCAL max_value,_vmin:dword
   
   mov edx,lpRect
   mov eax,[edx]
   .if eax<=0
      ret
   .endif
   mov eax,[edx+4]
   .if eax<=0
      ret
   .endif
   
   mov esi,cvArrImage   
   push [esi].IplImage._width
   pop p.x
   push [esi].IplImage.height
   pop p.y
   invoke cvCreateImage,p,8,3
   mov img,eax
   
   mov edi,img
   push [esi].IplImage.origin
   pop [edi].IplImage.origin
   
   
   invoke cvCreateImage,p,8,3
   mov hsv,eax
   
   invoke cvCreateImage,p,8,1
   mov hue,eax
   
   invoke cvCreateImage,p,8,1
   mov _mask,eax
   
   invoke cvCreateImage,p,8,1
   mov backproject,eax
   
   push 320
   pop p.x
   push 200
   pop p.y
   
   invoke cvCreateImage,p,8,3
   mov histimg,eax
   
   invoke cvSetZero,histimg
   
   lea eax,dim_arr
   mov tmp2,eax
   invoke cvCreateHist,1,addr hdims,CV_HIST_ARRAY,addr tmp2,1
   mov hist,eax
   
   invoke cvCvtColor,esi,hsv,CV_RGB2HSV
   
   push 0
   fild dword ptr [esp]
   fstp tmpsc.v1
   pop eax
   fild smin
   fstp tmpsc.v2
   invoke MIN2,vmin,vmax
   push eax
   fild dword ptr[esp]
   pop eax
   fstp tmpsc.v3
   push 0
   fild dword ptr[esp]
   fstp tmpsc.v4
   pop eax
   
   push 180
   fild dword ptr[esp]
   fstp tmpsc2.v1
   pop eax
   push 256
   fild dword ptr[esp]
   fstp tmpsc2.v2
   pop eax
   invoke MAX2,vmin,vmax
   push eax
   fild dword ptr[esp]
   fstp tmpsc2.v3
   pop eax
   push 0
   fild dword ptr[esp]
   fstp tmpsc2.v4
   pop eax
   
   
   invoke cvInRangeS,hsv,tmpsc,tmpsc2,_mask
   invoke cvSplit,hsv,hue,0,0,0
   
   mov edx,lpRect
   push [edx]
   pop r.left
   push [edx+4]
   pop r.top
   push [edx+8]
   pop r.right
   push [edx+12]
   pop r.bottom
   
   fld CDBL(0.0)
   fstp max_value
      
   invoke cvSetImageROI,hue,r
   invoke cvSetImageROI,_mask,r
      invoke cvCalcArrHist,addr hue,hist,0,_mask
      invoke cvGetMinMaxHistValue,hist,0,addr max_value,0,0
      mov edx,hist
      invoke cvConvertScale,[edx].CvHistogram.bins,[edx].CvHistogram.bins,1,0
   invoke cvResetImageROI,hue
   invoke cvResetImageROI,_mask
   
   invoke cvCalcArrBackProject,addr hue,backproject,hist
   
   push CV_TERMCRIT_EPS or CV_TERMCRIT_ITER
   pop ctc._type
   push 10
   pop ctc.max_iter
   fld CDBL(1.0)
   fstp ctc.epsilon
   invoke cvAnd,backproject,_mask,backproject,0
   invoke cvCamShift,backproject,r,ctc,addr track_comp,addr data
   
   invoke cvCvtColor,backproject,hsv,CV_GRAY2RGB
   invoke fCopyIplImageToDC,hsv,DC
   
   mov edx,hist
   mov edx,[edx].CvHistogram.bins
   mov edx,[edx]
   
   .if edx==0
      invoke TextOut,DC,0,200,CADD("Error"),5
   .else
      invoke TextOut,DC,0,200,CADD("Oke"),3
   .endif
   
   
   fld max_value
   fstp tmp
   invoke FloatToStr,tmp,addr buff
   invoke TextOut,DC,0,50,addr buff,6
   
   fld data.center.y
   fstp tmp
   invoke FloatToStr,tmp,addr buff
   invoke TextOut,DC,0,80,addr buff,6
   
   
   invoke cvReleaseHist,addr hist
   invoke cvReleaseImage,addr hsv
   invoke cvReleaseImage,addr hue
   invoke cvReleaseImage,addr _mask
   invoke cvReleaseImage,addr backproject
   invoke cvReleaseImage,addr histimg
   
   
   ret
ObjectTrack2 endp

Everything seems work fine, but the back projection buffer is blank, I dont know where is my mistake. Anyone can help?

Here is how I used it
Quote
   invoke cvLoadImage,addr buff,1
   .if eax!=0
      mov img,eax
      invoke fCopyIplImageToDC,eax,main_screen.DC
   ;   xchg edx,eax
      invoke ObjectTrack2,img,main_screen.DC,addr rMouse
      
;      invoke dw2a,edx,addr buff
;      invoke TextOut,main_screen.DC,0,0,addr buff,eax
      invoke cvReleaseImage,addr img
   .endif   

[attachment deleted by admin]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08