forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VideoWriter example and code working as expected, tested with MP4 and…
… AVI files Signed-off-by: deadprogram <[email protected]>
- Loading branch information
1 parent
edc917a
commit 17d4745
Showing
5 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// What it does: | ||
// | ||
// This example uses the VideoCapture class to capture video from a connected webcam, | ||
// and save it to a video file on disk | ||
// | ||
// How to run: | ||
// | ||
// savevideo [camera ID] [video file] | ||
// | ||
// go run ./examples/savevideo.go 0 testvideo.mp4 | ||
// | ||
// +build example | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
opencv3 ".." | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
fmt.Println("How to run:\n\tsavevideo [camera ID] [video file]") | ||
return | ||
} | ||
|
||
deviceID, _ := strconv.Atoi(os.Args[1]) | ||
saveFile := os.Args[2] | ||
|
||
webcam := opencv3.NewVideoCapture() | ||
defer webcam.Delete() | ||
|
||
writer := opencv3.NewVideoWriter() | ||
defer writer.Delete() | ||
|
||
if ok := webcam.OpenDevice(deviceID); !ok { | ||
fmt.Printf("error opening device: %v\n", deviceID) | ||
} | ||
|
||
img := opencv3.NewMat() | ||
defer img.Delete() | ||
|
||
if ok := webcam.Read(img); !ok { | ||
fmt.Printf("cannot read device %d\n", deviceID) | ||
return | ||
} | ||
|
||
writer.OpenWithMat(saveFile, 25, img) | ||
|
||
for i := 0; i < 100; i++ { | ||
if ok := webcam.Read(img); !ok { | ||
fmt.Printf("cannot read device %d\n", deviceID) | ||
return | ||
} | ||
if img.Empty() { | ||
continue | ||
} | ||
|
||
writer.Write(img) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters