Page 4 of 5

Re: get live film from a camera by ported usb or other

Posted: Fri Nov 01, 2013 12:29 am
by Mythros
Yeaaaa, no thank you. I do NOT like C. I will stick with the languages I know & love, best! ^_^

Thanks anyway!

Anyways, be back in a few minutes. Gonna ATTEMPT to try the LIB.

Re: get live film from a camera by ported usb or other

Posted: Fri Nov 01, 2013 7:59 pm
by JHPJHP
Updated
- added popup menu to each example
- added custom icon to each example
- removed "styles" from each examples window
-- #WS_MAXIMIZEBOX | #WS_MINIMIZEBOX | #WS_SIZEBOX
- various bug fixes and updates

Cheers!

Re: get live film from a camera by ported usb or other

Posted: Fri Nov 01, 2013 8:13 pm
by Mythros
@JHP, Can you add the 3D plot system that Python allows for?

I've been testing ALOT, and so far, all of your lib upgrades for OpenCV have worked! =D

Re: get live film from a camera by ported usb or other

Posted: Sat Nov 02, 2013 7:36 am
by JHPJHP
Hi Mythros,

I won't be able to proceed any further with the OpenCV development - sorry. I only took a crack at it to break up the monotony of the current projects I'm working on. I may from time to time add some functionality, but it will be sporadic at best. If you decide to take up the challenge and have any questions, post your code and I or the numerous PureBasic contributors will try to help as best we can.

Had the following changes already in the works
- updated the canny.pb example to include auto-threshold
- updated the examples to include an additional popup menu item
-- capture.pb, captureall.pb, video.pb: Capture / Pause - Exit
--- capture.pb, captureall.pb: opens paused
--- video.pb: opens capturing
-- canny.pb, flip.pb, gray.pb, swap1.pb, swap2.pb: Open - Exit
-- show.pb: Exit

JHPJHP

Re: get live film from a camera by ported usb or other

Posted: Sat Nov 02, 2013 12:23 pm
by AAT
JHP, thank you very much for your hard work!

Your set of OpenCV libraries will work in Windows Vista or in Windows 7.
For Windows XP 32 bit (like me)a set of libraries for MS Visual C 10 is required:
http://rghost.ru/49883548 - 14 days
or
http://www.fileswap.com/dl/USpJnxIp4/

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 12:55 am
by JHPJHP
Thanks AAT - I appreciate the Kudos... and the additional DLL's for XP support.
:wink: You started the ball rolling: http://www.purebasic.fr/english/viewtop ... 12&t=48212

------------------------------------

The following example (embedded.pb), the new DLL's, and some minor changes have been included in the download.

Embedded the OpenCV video into a PureBasic window in the following stripped down example (this seemed a must before signing off):
- updated to include the Canny effect via toggle button

Code: Select all

IncludeFile "opencv.pbi"

Repeat
  nCreate + 1
  *capture = cvCreateCameraCapture(0)
  Delay(500)
Until nCreate = 5 Or *capture

If *capture
  *image.IplImage
  *edges.IplImage
  cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_DEFAULT)
  cvMoveWindow(#CV_WINDOW_NAME, -1000, -1000)
  cvResizeWindow(#CV_WINDOW_NAME, 640, 480)
  window_handle = cvGetWindowHandle(#CV_WINDOW_NAME)
  hWnd = GetParent_(window_handle)
  ShowWindow_(hWnd, #SW_HIDE)

  If OpenWindow(0, 0, 0, 640, 540, "Embedded Webcam", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetParent_(window_handle, WindowID(0))
    ButtonGadget(0, 10, 490, 620, 40, "Toggle to change the webcam view between Normal and Canny effect", #PB_Button_Toggle)

    Repeat
      *image = cvQueryFrame(*capture)

      If *image
        If GetGadgetState(0)
          *edges = cvCreateImage(*image\width, *image\height, #IPL_DEPTH_8U, 1)
          cvCvtColor(*image, *edges, #CV_BGR2GRAY, 1)
          threshold.d = cvThreshold(*edges, *edges, 0, 255, #CV_THRESH_BINARY + #CV_THRESH_OTSU)
          cvCanny(*image, *edges, threshold * 0.5, threshold, 3, #False)
        Else
          *edges = *image
        EndIf

        If *edges
          cvShowImage(#CV_WINDOW_NAME, *edges)
          cvWaitKey(1)
        EndIf
      EndIf
    Until WindowEvent() = #PB_Event_CloseWindow
  EndIf
  cvDestroyWindow(#CV_WINDOW_NAME)
  cvReleaseCapture(@*capture)
  cvReleaseImage(@*edges)
  cvReleaseImage(@*image)
EndIf
CloseLibrary(highgui246)
Cheers!

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 5:09 am
by AAT
Exellent!
Now it's possible to use standard menus in OpenCV apps or to insert live video with effects in other pb programs.
Thanks!

P.S. What about changing (switching) real video resolutions?
I can't set resolution to 1280*1024 for my webcam with VfW but it's possible in amcap.exe (DirectShow) :(

Good luck!

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 7:03 am
by JHPJHP
Hi AAT,

Setting the resolution can be done via cvSetCaptureProperty
- added cvSetCaptureProperty & cvGetCaptureProperty to opencv.pbi

Updated: opencv.pbi
- added cvSmooth effect
-- changed embedded.pb
--- cvSmooth currently set for #CV_BLUR


Things to consider when setting the resolution
- your webcam's supported resolutions
- window size (OpenCV & PureBasic)
-- cvResizeWindow(#CV_WINDOW_NAME, 640, 480)
- instead of testing the max. size - try a lower resolution to prove that it's working
- cvNamedWindow supports two settings
-- #CV_WINDOW_DEFAULT
-- #CV_WINDOW_AUTOSIZE

NB*: Even if your webcam only supports 640x480 you can still stretch the window to what ever size you like.
I won't be able to proceed any further with the OpenCV development - sorry. I only took a crack at it to break up the monotony of the current projects I'm working on. I may from time to time add some functionality, but it will be sporadic at best. If you decide to take up the challenge and have any questions, post your code and I or the numerous PureBasic contributors will try to help as best we can.
JHPJHP

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 9:31 am
by AAT
JHPJHP, thank you very much!
I won't be able to proceed any further with the OpenCV development
I understand you :)

So long!

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 9:35 am
by JHPJHP
AAT - you beat me to the post :wink: I decided to add one more example...
- added resolution.pb

NOTE:
- I set the resolutions to my personal webcam
- because I only have 640 x 480 max - when I choose 800 x 600 - the resolution remains at 640 x 480

Cheers!

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 11:38 am
by AAT
Yesss! It works!
My heartfelt thanks to you from the cold Siberia, JHPJHP! :D

Cheers!

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 3:20 pm
by Mythros
KUDOS JHP, THIS IS AMAZING! O_O I didn't think you could CHANGE the resolution! :D

I have a small question. Is there a way you can possibly add that Kinect thing from the german forums into the OpenCV code? I can't quite wrap my head around it.

Thanks once again! :D

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 8:04 pm
by JHPJHP
Hi Mythros,

Concerning your question about merging the OpenCV library with the script found in the post IdeasVacuum submitted from Code Laboratories, and its webcam library - is not possible, they are two separate entities.

--------------------

Updated resolution.pb
- added a BindEvent to the Checkbox Gadget
- cleaner transition between frame resizing

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 8:50 pm
by Mythros
<3 KUDOS to YOU, JHP! I think I'm going to add a PERMANENT link for the latest OpenCV so that beginners have access to it as well! :D

Re: get live film from a camera by ported usb or other

Posted: Sun Nov 03, 2013 10:23 pm
by JHPJHP
In that case...

I made some naming convention changes, and a small update to the example resolution.pb (now pb_resolution.pb).
- cv_... (utilizes OpenCV window)
- pb_... (embedded into purebasic window)

From this point forward I will submit any changes / updates to your new post... I'm guessing it will be located in Tricks 'n' Tips?

Cheers!