这是我的密码
class VideoWriterTest {
@Test
fun write() {
OpenCV.loadLocally()
println("opencv version=${Core.getVersionString()}")
val fourcc = VideoWriter.fourcc('a', 'c', 'v', '1')
val size1 = Size(100.0, 100.0)
val outputFile= File("temp.mp4")
outputFile.delete()
val writer = VideoWriter(outputFile.path, fourcc, 30.0, size1)
println( writer.backendName)
assertTrue(writer.isOpened)
}
}
当运行时,我得到这个错误。
opencv version=4.6.0
cv::Exception: OpenCV(4.6.0) /home/runner/work/opencv/opencv/opencv-4.6.0/modules/videoio/src/cap.cpp:666: error: (-215:Assertion failed) api != 0 in function 'getBackendName'
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.6.0) /home/runner/work/opencv/opencv/opencv-4.6.0/modules/videoio/src/cap.cpp:666: error: (-215:Assertion failed) api != 0 in function 'getBackendName'
]
at app//org.opencv.videoio.VideoWriter.getBackendName_0(Native Method)
at app//org.opencv.videoio.VideoWriter.getBackendName(VideoWriter.java:380)
at app//com.katalisindonesia.heavi.analytic.service.VideoWriterTest.write(VideoWriterTest.kt:26)
我用的是org.openpnp:opencv:4.6.0-0
。有什么想法吗?
编辑:这段代码在macOS上工作,但在linux上不工作。
EDIT2:macOS中的输出
opencv version=4.6.0
AVFOUNDATION
1条答案
按热度按时间ktecyv1j1#
我把代码修改成这个
然后就过去了
输出:
结论:
1.文件名必须使用
.avi
扩展名