Page 1 of 1

OpenCV very low performance on Camera settings Change

Posted: Fri Jun 02, 2017 12:57 am
by LiK137
Hi,
Below the slightly modified "pb_cam_resolution.pb" and "pb_cam_preferences.pb" from openCV examples.

Code: Select all

IncludeFile "includes/cv_functions.pbi"

Global *capture.CvCapture
Global DefBrightness.d, MaxBrightness.d, MinBrightness.d, DefContrast.d, MaxContrast.d, MinContrast.d
Global DefGamma.d, MaxGamma.d, MinGamma.d, DefSaturation.d, MaxSaturation.d, MinSaturation.d
Global DefHue.d, MaxHue.d, MinHue.d, DefSharpness.d, MaxSharpness.d, MinSharpness.d
Global DefExposure.d, MaxExposure.d, MinExposure.d

Global Dim size.Size(0)

Define   FrameWidth.l = 640, FrameHeight.l = 480


#CV_WINDOW_NAME = "PureBasic Interface to OpenCV"
#CV_DESCRIPTION = "Creates an interface to the webcam's parameters such as brightness, contrast, hue, etc." + #LF$ + #LF$ +
                  "NOTE:" + #LF$ + "A preference file is created if one cannot be found."

Procedure ReadCamData()
  Preference.s = ProgramFilename()+":preferences.txt"
  If Not OpenPreferences(Preference)
    CreatePreferences(Preference)
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS)
    WritePreferenceLong("DefBrightness", defValue)
    
    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxBrightness", retMaxValue)
    WritePreferenceLong("MinBrightness", retMinValue)
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST)
    WritePreferenceLong("DefContrast", defValue)

    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxContrast", retMaxValue)
    WritePreferenceLong("MinContrast", retMinValue)

    
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA)
    WritePreferenceLong("DefGamma", defValue)
    
    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxGamma", retMaxValue)
    WritePreferenceLong("MinGamma", retMinValue)
    
    
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION)
    WritePreferenceLong("DefSaturation", defValue)

    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxSaturation", retMaxValue)
    WritePreferenceLong("MinSaturation", retMinValue)
    
    
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_HUE)
    WritePreferenceLong("DefHue", defValue)

    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_HUE, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_HUE)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_HUE, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_HUE)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxHue", retMaxValue)
    WritePreferenceLong("MinHue", retMinValue)
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS)
    WritePreferenceLong("DefSharpness", defValue)

    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxSharpness", retMaxValue)
    WritePreferenceLong("MinSharpness", retMinValue)
    
    
    defValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE)
    WritePreferenceLong("DefExposure", defValue)
    
    minValue = defValue : retMinValue = defValue
    maxValue = defValue : retMaxValue = defValue
    
    Repeat 
      
      minValue - 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE, minValue)
        retMinValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE)

      FixWindowUnresponsive()
      
    Until  minValue <> retMinValue
    Repeat 
      maxValue + 1
        cvSetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE, maxValue)
        retMaxValue = cvGetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE)
      
      FixWindowUnresponsive()
      
    Until  maxValue <> retMaxValue
    
    If retMaxValue < defValue : retMaxValue = defValue : EndIf
    If retMinValue > defValue : retMinValue = defValue : EndIf
    WritePreferenceLong("MaxExposure", retMaxValue)
    WritePreferenceLong("MinExposure", retMinValue)
    
  EndIf
  
  
  DefBrightness = ReadPreferenceLong("DefBrightness", 1)
  DefContrast =  ReadPreferenceLong("DefContrast", 1)
  DefGamma = ReadPreferenceLong("DefGamma", 1)
  DefSaturation = ReadPreferenceLong("DefSaturation", 1)
  DefHue = ReadPreferenceLong("DefHue", 1)
  DefSharpness = ReadPreferenceLong("DefSharpness", 1)
  DefExposure = ReadPreferenceLong("DefExposure", 1)
  MaxBrightness = ReadPreferenceLong("MaxBrightness", 1)
  MaxContrast = ReadPreferenceLong("MaxContrast", 1)
  MaxGamma = ReadPreferenceLong("MaxGamma", 1)
  MaxSaturation = ReadPreferenceLong("MaxSaturation", 1)
  MaxHue = ReadPreferenceLong("MaxHue", 1)
  MaxSharpness = ReadPreferenceLong("MaxSharpness", 1)
  MaxExposure = ReadPreferenceLong("MaxExposure", 1)
  MinBrightness = ReadPreferenceLong("MinBrightness", 1)
  MinContrast =  ReadPreferenceLong("MinContrast", 1)
  MinGamma = ReadPreferenceLong("MinGamma", 1)
  MinSaturation = ReadPreferenceLong("MinSaturation", 1)
  MinHue = ReadPreferenceLong("MinHue", 1)
  MinSharpness = ReadPreferenceLong("MinSharpness", 1)
  MinExposure = ReadPreferenceLong("MinExposure", 1)
  
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS, DefBrightness)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST, DefContrast)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA, DefGamma)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION, DefSaturation)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_HUE, DefHue)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS, DefSharpness)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE, DefExposure)

EndProcedure

Procedure SetResolution(nWidth.l, nHeight.l)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH, nWidth)
  cvSetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT, nHeight)
EndProcedure

Procedure ResolutionList(MaxWidth.l = 8192, MinWidth.l = 50, rStep.l = 50)
  FrameWidth.l  = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
  FrameHeight.l = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT)
  
  Select #True
    Case Bool(MaxWidth < FrameWidth)
      MaxWidth = FrameWidth
    Case Bool(MinWidth > FrameWidth)
      MinWidth = FrameWidth
    Case Bool(MinWidth < 50)
      MinWidth = 50
  EndSelect

  For rtnCount.l = 1 To (MaxWidth - MinWidth)/rStep
    
    cvSetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH, rtnCount * rStep + MinWidth)
    cvSetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT, rtnCount * rStep + MinWidth)
    
    tmpFrameWidth = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
    tmpFrameHeight = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT)
    
    If Not FindString(SearchString.s, Str(tmpFrameWidth) + ";")
      ReDim size(ArraySize(size()) + 1)
      size(ArrayCount)\cx = tmpFrameWidth
      size(ArrayCount)\cy = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_HEIGHT)
      FrameWidth = size(ArrayCount)\cx : FrameHeight = size(ArrayCount)\cy
      SearchString + Str(tmpFrameWidth) + ";"
      ArrayCount + 1
    EndIf
  Next
  ProcedureReturn ArraySize(size())
EndProcedure

Macro _Resolute      
;{ GatherVData      
      ResizeImage(pbImage, nWidth, nHeight)
      SetResolution(nWidth, nHeight)
      
      ResizeWindow(0, 0, 0, nWidth+140, nHeight+33)
      ResizeGadget(camGadget, 0, 0, nWidth, nHeight)
      
      ResizeGadget(txtBrightness, nWidth+10, 25, 60, 20)
      ResizeGadget(txtContrast, nWidth+10, 50, 60, 20)
      ResizeGadget(txtGamma, nWidth+10, 75, 60, 20)
      ResizeGadget(txtSaturation, nWidth+10, 100, 60, 20)
      ResizeGadget(txtHue, nWidth+10, 125, 60, 20)
      ResizeGadget(txtSharpness, nWidth+10, 150, 60, 20)
      ResizeGadget(txtExposure, nWidth+10, 175, 60, 20)
      ResizeGadget(txtResolution, nWidth+10, 200, 60, 20)
      
      ResizeGadget(Braytnes, nWidth+65, 20, 50, 20)
      ResizeGadget(Contrast, nWidth+65, 45, 50, 20)
      ResizeGadget(Gamma, nWidth+65, 70, 50, 20)
      ResizeGadget(Saturation, nWidth+65, 95, 50, 20)
      ResizeGadget(Hue, nWidth+65, 120, 50, 20)
      ResizeGadget(Sharpness, nWidth+65, 145, 50, 20)
      ResizeGadget(Exposure, nWidth+65, 170, 50, 20)
      
      ResizeGadget(Resolution, nWidth+65, 195, 75, 20)
;}     
EndMacro      

Repeat
  nCreate + 1
  *capture = cvCreateCameraCapture(#CV_CAP_ANY)
Until nCreate = 5 Or *capture

*image.IplImage
If *capture
  ReadCamData()
  
  If OpenWindow(0, 0, 0, FrameWidth, FrameHeight, #CV_WINDOW_NAME, #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
    
    RedrawWindow_(WindowID(0),0,0,#RDW_INVALIDATE | #RDW_ERASE) 
    UpdateWindow_(WindowID(0)) 
    
    HideFromTaskBar(WindowID(0),1)
    StickyWindow(0,#True)
    ResizeWindow(0,#PB_Ignore,#PB_Ignore,FrameWidth,FrameHeight)
    SmartWindowRefresh(0,0)
    HideWindow(0,1)
    
    SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) & ~(#WS_CAPTION | #WS_SYSMENU) | #WS_THICKFRAME)
    nSize.l = ResolutionList(1280,640, 80)
    If nSize
    
      nWidth.l = size(ArraySize(size()) - 1)\cx : nHeight.l = size(ArraySize(size()) - 1)\cy
      ResizeWindow(0, 0, 0, nWidth+140, nHeight+33)
      
      pbImage.i = CreateImage(#PB_Any, nWidth, nHeight)
      
      camGadget.l = ImageGadget(#PB_Any, 0, 0, nWidth, nHeight, ImageID(pbImage))
      SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) & ~#WS_THICKFRAME | (#WS_CAPTION | #WS_SYSMENU))
        
      txtBrightness.l = TextGadget(#PB_Any, nWidth+10, 25, 60, 20, "Brightness:", #PB_Text_Right)
      txtContrast.l = TextGadget(#PB_Any, nWidth+10, 50, 60, 20, "Contrast:", #PB_Text_Right)
      txtGamma.l = TextGadget(#PB_Any, nWidth+10, 75, 60, 20, "Gamma:", #PB_Text_Right)
      txtSaturation.l = TextGadget(#PB_Any, nWidth+10, 100, 60, 20, "Saturation:", #PB_Text_Right)
      txtHue.l = TextGadget(#PB_Any, nWidth+10, 125, 60, 20, "Hue:", #PB_Text_Right)
      txtSharpness.l = TextGadget(#PB_Any, nWidth+10, 150, 60, 20, "Sharpness:", #PB_Text_Right)
      txtExposure.l = TextGadget(#PB_Any, nWidth+10, 175, 60, 20, "Exposure:", #PB_Text_Right)
      txtResolution.l = TextGadget(#PB_Any, nWidth+10, 200, 60, 20, "Resolution:", #PB_Text_Right)
      
      Braytnes.l = SpinGadget(#PB_Any, nWidth+65, 20, 50, 20, MinBrightness, MaxBrightness, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Braytnes, #PB_Gadget_BackColor, $F0F0F0)
      Contrast.l = SpinGadget(#PB_Any, nWidth+65, 45, 50, 20, MinContrast, MaxContrast, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Contrast, #PB_Gadget_BackColor, $F0F0F0)
      Gamma.l = SpinGadget(#PB_Any, nWidth+65, 70, 50, 20, MinGamma, MaxGamma, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Gamma, #PB_Gadget_BackColor, $F0F0F0)
      Saturation.l = SpinGadget(#PB_Any, nWidth+65, 95, 50, 20, MinSaturation, MaxSaturation, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Saturation, #PB_Gadget_BackColor, $F0F0F0)
      Hue.l = SpinGadget(#PB_Any, nWidth+65, 120, 50, 20, MinHue, MaxHue, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Hue, #PB_Gadget_BackColor, $F0F0F0)
      Sharpness.l = SpinGadget(#PB_Any, nWidth+65, 145, 50, 20, MinSharpness, MaxSharpness, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Sharpness, #PB_Gadget_BackColor, $F0F0F0)
      Exposure.l = SpinGadget(#PB_Any, nWidth+65, 170, 50, 20, MinExposure, MaxExposure, #PB_Spin_ReadOnly | #PB_Spin_Numeric) : SetGadgetColor(Exposure, #PB_Gadget_BackColor, $F0F0F0)
      
      Resolution.l = ComboBoxGadget(#PB_Any, nWidth+65, 195, 75, 20)
      For rtnCount.l = 0 To nSize - 1
        AddGadgetItem(Resolution, -1, Str(size(rtnCount)\cx) + "x" + Str(size(rtnCount)\cy))  
      Next
      
      SetGadgetState(Resolution, nSize - 1)
      SetGadgetState(Braytnes, DefBrightness)
      SetGadgetState(Contrast, DefContrast)
      SetGadgetState(Gamma, DefGamma)
      SetGadgetState(Saturation, DefSaturation)
      SetGadgetState(Hue, DefHue)
      SetGadgetState(Sharpness, DefSharpness)
      SetGadgetState(Exposure, DefExposure)
      
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, 10)
      ToolTip(GadgetID(camGadget), #CV_DESCRIPTION)
      
      While WindowEvent():Wend  ; (2)__-=::[ PROCESS ALL EVENTS NOW (gadget creation etc.) ]::=-__
      HideWindow(0,0)      ; (3)__-=::[ SHOW/UN-HIDE THE WINDOW                       ]::=-__
      
     _Resolute

      Repeat
        Event = WindowEvent()
  
        Select Event
          Case #PB_Event_Gadget
            Select EventGadget()
              Case Braytnes
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Braytnes) 
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Braytnes)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_BRIGHTNESS, val) : Debug "Val00: "+val
                WritePreferenceLong("DefBrightness", val)
              Case Contrast
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Contrast)
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Contrast)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_CONTRAST, val) : Debug "Val00: "+val
                WritePreferenceLong("DefContrast", val) 
              Case Gamma
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Gamma)
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Gamma)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_GAMMA, val) : Debug "Val00: "+val
                WritePreferenceLong("DefGamma", val)
              Case Saturation
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Saturation)
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Saturation)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_SATURATION, val) : Debug "Val00: "+val
                WritePreferenceLong("DefSaturation", val)
              Case Hue
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Hue)
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Hue)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_HUE, val) : Debug "Val00: "+val
                WritePreferenceLong("DefHue", val)
              Case Sharpness
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Sharpness)
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Sharpness)
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_SHARPNESS, val) : Debug "Val00: "+val
                WritePreferenceLong("DefSharpness", val)
              Case Exposure
                Select EventType()
                  Case #PB_EventType_Up
                    val.l = GetGadgetState(Exposure) : Debug "Val00: "+val
                  Case #PB_EventType_Down
                    val.l = GetGadgetState(Exposure) : Debug "Val11: "+val
                EndSelect
                cvSetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE, val) : Debug "Val22: "+val
                WritePreferenceLong("DefExposure", val)
              Case Resolution                
                Select EventType()
                  Case #PB_EventType_Change
                    Resolution$ = GetGadgetText(Resolution)
                    nPosition = FindString(Resolution$, "x")
                    nWidth = Val(Left(Resolution$, nPosition - 1))
                    nHeight = Val(Mid(Resolution$, nPosition + 1))
                    
                    _Resolute
                    
                EndSelect
            EndSelect
          Case #PB_Event_CloseWindow : Break
          Default
            *image = cvQueryFrame(*capture)
  
            If *image
              cvFlip(*image, #Null, 1)
              OpenCV2PBImage_ASM(*image, pbImage, *image\width, *image\height)
              SetGadgetState(camGadget, ImageID(pbImage))
            EndIf
          EndSelect
      ForEver
    EndIf  
  EndIf
  FreeImage(pbImage)
  cvReleaseCapture(@*capture)
  ClosePreferences()
Else
  MessageRequester(#CV_WINDOW_NAME, "Unable to connect to a webcam - operation cancelled.", #MB_ICONERROR)
EndIf
1st: GadgetDraw on first start is lagging. (If camera image is for some reason too dark or bright then lagging increases)
2nd: Changing Camera settings negatively affect program overall performance
3rd: Couldn't make option for listing/choosing existing cameras by means of OpenCV
4th: cvShowImage(#CV_WINDOW_NAME, *resize) like native function for using/showing with gadgets (Image, ButtonImage, Canvas or Custom gadgets)

Thank You very much