Had some extra time so I created this example: ( of course there might already be an example of this )
It loads a JPG image, selects a section then it zooms back out to display the whole JPG on an AVI.
On video editing it is usually called the "Ken Burnes effect" and it is used to add "motion" to still photos.
save it as CV_Zoom_JHP.pb along with all the open cv examples and in compiler options set directories
to "binaries\" , the program will use \binaries\images\weight3.jpg as JPG and output /Videos/zoom.avi
it needs DIVX codec so if it does not run get the DIVX codec or change the codec to MSVC
[edit]
I downloaded the latest "OpenCV_Win32" JHP has at his site (Sept,29,2017). (OpenCV v2.4.13.3)
Code: Select all
IncludeFile "includes/cv_functions.pbi"
;CV_Zoom_JHP.pb
Global *original.IplImage,*show.IplImage,*save.IplImage
Global zo_x=170,zo_y=80,zo_w=360,zo_h=300 ; section of picture to zoom from currently an e=mc2 eye
Global outputw=960,outputh=780,fps=30 ; final output dimentions of AVI file
#CV_WINDOW_NAME = "PureBasic Interface to OpenCV"
#CV_DESCRIPTION = "zooms on a jpg picture, Ken burns effect; saving it as an AVI movie"
#img = "images/weight3.jpg"
;LOAD IMAGE
If FileSize(#img)
Debug #img
Else
MessageRequester("Image not found","please verify image location")
End
EndIf
*writer = cvCreateVideoWriter("../Videos/zoom.avi", CV_FOURCC("D", "I", "V", "X"), fps,outputw,outputh, #True); create our 30 frames/s AVI container
*original = cvLoadImage(#img, #CV_LOAD_IMAGE_ANYDEPTH | #CV_LOAD_IMAGE_ANYCOLOR) ; Load image any size
*save = cvCreateImage(outputw, outputh, #IPL_DEPTH_8U, *original\nChannels) ; create image to our AVI dimentions
cvResize(*original, *save, #CV_INTER_AREA) ;resize original image to our AVI dimentions
cvSetImageROI(*save, zo_x, zo_y, zo_w, zo_h) ; select e=mc2 eye from now resized *save picture
*show = cvCreateImage(zo_w, zo_h, #IPL_DEPTH_8U, *original\nChannels) ;create a temp buffer to show a section of image
;CREATE first FRAME
cvcopy(*save, *show,#Null)
*nsave = cvCreateImage(outputw, outputh, #IPL_DEPTH_8U, *original\nChannels)
cvresize(*show,*nsave,#cv_INTER_AREA)
cvResetImageROI(*save)
cvReleaseImage(@*show)
;SAVE IMAGES TO AVI MOVIE
For i = 1 To 6*fps ; six seconds at 30 frames per second
; For j = 1 To 2 ; add this For Next loop to write 2 frames of the same picture to slow it down
cvWriteFrame(*writer, *nsave)
; Next
If roix >0 :roix=zo_x-i :EndIf ; decrease x until 0
If roiy >0 :roiy=zo_y-i :EndIf ; decrease y until 0
roiw=zo_w+(i*4) ; increase width
roih=zo_h+(i*4) ; increase height
If roiw > outputw: roiw = outputw:EndIf ;dont get bigger than our output width
If roih > outputh: roih = outputh:EndIf ; dont get bigger than our output height
cvSetImageROI(*save, roiy, roix, roiw, roih) ; set our ROI with new dimentions
*show = cvCreateImage(roiw, roih, #IPL_DEPTH_8U, *original\nChannels) ; create an image to copy to
cvcopy(*save, *show,#Null) ; copy ROI to new image
cvResetImageROI(*save) ;reset ROI
cvresize(*show,*nsave,#cv_INTER_AREA) ; copy this new section to full output
cvReleaseImage(@*show)
Next
cvReleaseVideoWriter(@*writer)
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari