x1ongzhu 6 лет назад
Родитель
Сommit
24be30cf71

+ 99 - 9
log.txt

@@ -121,7 +121,7 @@ Caused by: java.io.EOFException: Can not read response from server. Expected to
 	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615)
 	... 33 more
 [2019-01-30 16:25:43] [WARN ] - A ConnectionTest has failed, reporting that all previously acquired Connections are likely invalid. The pool will be reset.
-[2019-01-30 16:25:43] [WARN ] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@134f8ef6] to process 'after' execution for test: method [public void RecognitionTest.testRecognition()], instance [RecognitionTest@5a90265a], exception [null]
+[2019-01-30 16:25:43] [WARN ] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@134f8ef6] to process 'after' execution for test: method [public void VideoProcessTest.testRecognition()], instance [VideoProcessTest@5a90265a], exception [null]
 org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.
 	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:297)
 	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:853)
@@ -247,7 +247,7 @@ Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
 [2019-01-31 12:17:10] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 14:58:02] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 15:03:02] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: libopencv_java401.dylib
-[2019-01-31 15:03:02] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [RecognitionTest@2234078]
+[2019-01-31 15:03:02] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [VideoProcessTest@2234078]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -304,7 +304,7 @@ Caused by: java.lang.UnsatisfiedLinkError: Expecting an absolute path of the lib
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108)
 	... 38 more
 [2019-01-31 15:06:40] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no libopencv_java401 in java.library.path
-[2019-01-31 15:06:40] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [RecognitionTest@2234078]
+[2019-01-31 15:06:40] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [VideoProcessTest@2234078]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -362,7 +362,7 @@ Caused by: java.lang.UnsatisfiedLinkError: no libopencv_java401 in java.library.
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108)
 	... 38 more
 [2019-01-31 15:07:16] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.library.path
-[2019-01-31 15:07:16] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [RecognitionTest@2234078]
+[2019-01-31 15:07:16] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [VideoProcessTest@2234078]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -420,7 +420,7 @@ Caused by: java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.libra
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108)
 	... 38 more
 [2019-01-31 15:08:03] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.library.path
-[2019-01-31 15:08:03] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [RecognitionTest@2234078]
+[2019-01-31 15:08:03] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [VideoProcessTest@2234078]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -478,7 +478,7 @@ Caused by: java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.libra
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108)
 	... 38 more
 [2019-01-31 15:09:42] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: Directory separator should not appear in library name: /Library/Java/Extensions/libopencv_java401.so
-[2019-01-31 15:09:42] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [RecognitionTest@2234078]
+[2019-01-31 15:09:42] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c41d037] to prepare test instance [VideoProcessTest@2234078]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -540,7 +540,7 @@ Caused by: java.lang.UnsatisfiedLinkError: Directory separator should not appear
 [2019-01-31 15:17:26] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 15:22:03] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 15:24:32] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.library.path
-[2019-01-31 15:24:32] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@554c4eaa] to prepare test instance [RecognitionTest@29fd8e67]
+[2019-01-31 15:24:32] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@554c4eaa] to prepare test instance [VideoProcessTest@29fd8e67]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -598,7 +598,7 @@ Caused by: java.lang.UnsatisfiedLinkError: no libopencv_java401.so in java.libra
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108)
 	... 38 more
 [2019-01-31 15:26:54] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no opencv_java401 in java.library.path
-[2019-01-31 15:26:54] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@554c4eaa] to prepare test instance [RecognitionTest@29fd8e67]
+[2019-01-31 15:26:54] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@554c4eaa] to prepare test instance [VideoProcessTest@29fd8e67]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -658,7 +658,7 @@ Caused by: java.lang.UnsatisfiedLinkError: no opencv_java401 in java.library.pat
 [2019-01-31 15:29:59] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 15:30:39] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-01-31 21:47:25] [WARN ] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'videoRecognitionServiceImpl' defined in file [/Users/drew/Projects/Java/shouyoudianjing/target/classes/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.class]: Instantiation of bean failed; nested exception is java.lang.UnsatisfiedLinkError: no opencv_java401 in java.library.path
-[2019-01-31 21:47:25] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@577f9109] to prepare test instance [RecognitionTest@4303b7f0]
+[2019-01-31 21:47:25] [ERROR] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@577f9109] to prepare test instance [VideoProcessTest@4303b7f0]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
@@ -1925,3 +1925,93 @@ Caused by: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Tesseract-OCR\
 [2019-02-28 18:58:51] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-02-28 19:01:34] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-02-28 19:01:54] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-26 09:33:03] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-26 09:34:08] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-26 09:55:43] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-27 17:04:19] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-27 17:05:02] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-27 17:06:26] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-27 17:06:54] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 15:59:17] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 16:00:26] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 16:02:40] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 16:03:46] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 16:29:40] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:03:30] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:13:39] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:14:41] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:22:59] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:23:06] [WARN ] - [Client]Unable to execute HTTP request: SocketException
+[2019-03-28 17:24:25] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:26:19] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:26:45] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-28 17:27:12] [WARN ] - [Client]Unable to execute HTTP request: SocketException
+[2019-03-28 17:27:54] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-29 09:48:49] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-29 09:50:25] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-29 09:52:17] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-03-29 09:53:18] [WARN ] - [Client]Unable to execute HTTP request: UnknownHost
+[2019-03-29 09:53:18] [WARN ] - [Client]Unable to execute HTTP request: UnknownHost
+[2019-03-29 09:53:19] [WARN ] - [Client]Unable to execute HTTP request: UnknownHost
+[2019-03-29 09:53:22] [WARN ] - [Client]Unable to execute HTTP request: UnknownHost
+[2019-03-29 09:53:22] [ERROR] - OSS上传异常:
+com.aliyun.oss.ClientException: UnknownHost
+	at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:68)
+	at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:67)
+	at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:121)
+	at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:67)
+	at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:89)
+	at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:130)
+	at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:108)
+	at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:574)
+	at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:119)
+	at com.aliyun.oss.OSSClient.putObject(OSSClient.java:412)
+	at com.aliyun.oss.OSSClient.putObject(OSSClient.java:399)
+	at com.izouma.awesomeadmin.service.OSSFileService.upload(OSSFileService.java:50)
+	at com.izouma.awesomeadmin.util.VideoProcessTool.uploadImage(VideoProcessTool.java:343)
+	at com.izouma.awesomeadmin.util.VideoProcessTool.processVideo(VideoProcessTool.java:72)
+	at VideoProcessTest.testVideo(VideoProcessTest.java:30)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:498)
+	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
+	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
+	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
+	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
+	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
+	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
+	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
+	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
+	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
+	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
+	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
+	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
+	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
+	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
+	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
+	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
+	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
+	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
+	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
+	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
+	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
+	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
+	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
+	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
+Caused by: java.net.UnknownHostException: microball.oss-cn-hangzhou.aliyuncs.com
+	at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
+	at java.net.InetAddress.getAllByName(InetAddress.java:1192)
+	at java.net.InetAddress.getAllByName(InetAddress.java:1126)
+	at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:262)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:161)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
+	at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:64)
+	... 41 more

+ 28 - 24
pom.xml

@@ -131,6 +131,9 @@
                 <configuration>
                     <source>${jdk.version}</source>
                     <target>${jdk.version}</target>
+                    <compilerArgs>
+                        <arg>-Dfile.encoding=UTF-8</arg>
+                    </compilerArgs>
                 </configuration>
             </plugin>
             <plugin>
@@ -986,7 +989,6 @@
             <scope>runtime</scope>
         </dependency>
 
-
         <dependency>
             <groupId>com.alipay.sdk</groupId>
             <artifactId>alipay-sdk-java</artifactId>
@@ -994,39 +996,41 @@
         </dependency>
 
         <dependency>
-            <groupId>net.sourceforge.tess4j</groupId>
-            <artifactId>tess4j</artifactId>
-            <version>4.3.1</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.slf4j</groupId>
-                    <artifactId>log4j-over-slf4j</artifactId>
-                </exclusion>
-            </exclusions>
+            <groupId>net.java.dev.jna</groupId>
+            <artifactId>jna</artifactId>
+            <version>4.1.0</version>
         </dependency>
 
         <dependency>
-            <groupId>net.sourceforge.lept4j</groupId>
-            <artifactId>lept4j</artifactId>
-            <version>1.11.0</version>
+            <groupId>cn.jpush.api</groupId>
+            <artifactId>jpush-client</artifactId>
+            <version>3.3.10</version>
         </dependency>
 
         <dependency>
-            <groupId>org.opencv.opencv</groupId>
-            <artifactId>opencv</artifactId>
-            <version>4.0.1</version>
+            <groupId>org.bytedeco</groupId>
+            <artifactId>javacv-platform</artifactId>
+            <version>1.4.4</version>
         </dependency>
-
         <dependency>
-            <groupId>net.java.dev.jna</groupId>
-            <artifactId>jna</artifactId>
-            <version>4.1.0</version>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>opencv-platform</artifactId>
+            <version>4.0.1-1.4.4</version>
         </dependency>
-
         <dependency>
-            <groupId>cn.jpush.api</groupId>
-            <artifactId>jpush-client</artifactId>
-            <version>3.3.10</version>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>ffmpeg-platform</artifactId>
+            <version>4.1-1.4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>tesseract-platform</artifactId>
+            <version>4.0.0-1.4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>leptonica-platform</artifactId>
+            <version>1.77.0-1.4.4</version>
         </dependency>
     </dependencies>
 

+ 1 - 9
src/main/java/com/izouma/awesomeadmin/service/VideoRecognitionService.java

@@ -1,8 +1,6 @@
 package com.izouma.awesomeadmin.service;
 
 import com.izouma.awesomeadmin.model.PlayerInfo;
-import org.opencv.core.Mat;
-import org.opencv.ml.SVM;
 
 import java.util.Map;
 
@@ -11,11 +9,5 @@ public interface VideoRecognitionService {
 
     void start(PlayerInfo playerInfo);
 
-    boolean matchGameOver(SVM svm, Mat inputImage);
-
-    String extractRank(Mat inputImage);
-
-    String extractGameTime(Mat inputImage);
-
-    Map<String, Object> stat(String videoPath);
+    Map<String, String> stat(String videoPath);
 }

+ 33 - 470
src/main/java/com/izouma/awesomeadmin/service/impl/VideoRecognitionServiceImpl.java

@@ -5,44 +5,16 @@ import com.izouma.awesomeadmin.model.PlayerInfo;
 import com.izouma.awesomeadmin.service.OSSFileService;
 import com.izouma.awesomeadmin.service.PlayerInfoService;
 import com.izouma.awesomeadmin.service.VideoRecognitionService;
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-import com.sun.jna.Platform;
-import net.sourceforge.tess4j.ITesseract;
-import net.sourceforge.tess4j.Tesseract;
-import net.sourceforge.tess4j.TesseractException;
-import org.apache.commons.lang.StringUtils;
-import org.hibernate.validator.internal.util.privilegedactions.GetResource;
-import org.opencv.core.*;
-import org.opencv.highgui.HighGui;
-import org.opencv.imgcodecs.Imgcodecs;
-import org.opencv.imgproc.Imgproc;
-import org.opencv.ml.SVM;
-import org.opencv.videoio.VideoCapture;
-import org.opencv.videoio.Videoio;
+import com.izouma.awesomeadmin.util.VideoProcessTool;
+import org.bytedeco.javacv.FrameGrabber;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import sun.misc.BASE64Encoder;
 
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-
-import static org.opencv.core.Core.ROTATE_90_COUNTERCLOCKWISE;
-import static org.opencv.core.Core.rotate;
-import static org.opencv.core.CvType.*;
-import static org.opencv.highgui.HighGui.*;
-import static org.opencv.imgcodecs.Imgcodecs.*;
-import static org.opencv.imgproc.Imgproc.*;
 
 @Service
 public class VideoRecognitionServiceImpl implements VideoRecognitionService {
@@ -51,34 +23,15 @@ public class VideoRecognitionServiceImpl implements VideoRecognitionService {
     private OSSFileService    ossFileService;
     @Autowired
     private PlayerInfoService playerInfoService;
+    private VideoProcessTool  videoProcessTool = new VideoProcessTool();
 
     public static  boolean                          DEBUG      = false;
-    private static Map<String, Map<String, Object>> resultMap  = new HashMap<>();
+    private static Map<String, Map<String, String>> resultMap  = new HashMap<>();
     private static Map<String, Long>                lastStat   = new HashMap<>();
     private static Map<String, Object>              processing = new HashMap<>();
 
     private ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
 
-    static {
-        System.out.println(System.getProperty("java.library.path"));
-        CLibrary.INSTANCE.setlocale(CLibrary.LC_ALL, "C");
-        CLibrary.INSTANCE.setlocale(CLibrary.LC_NUMERIC, "C");
-        CLibrary.INSTANCE.setlocale(CLibrary.LC_CTYPE, "C");
-        System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
-        System.loadLibrary("tesseract");
-    }
-
-    public interface CLibrary extends Library {
-        CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
-
-        int LC_CTYPE   = 0;
-        int LC_NUMERIC = 1;
-        int LC_ALL     = 6;
-
-        // char *setlocale(int category, const char *locale);
-        String setlocale(int category, String locale);
-    }
-
     @Override
     public boolean start(String videoPath) {
         if (processing.get(videoPath) != null) {
@@ -87,67 +40,18 @@ public class VideoRecognitionServiceImpl implements VideoRecognitionService {
         processing.put(videoPath, videoPath);
         lastStat.put(videoPath, System.currentTimeMillis());
         resultMap.remove(videoPath);
-        VideoCapture capture = new VideoCapture();
-        if (capture.open(videoPath)) {
-            System.out.println(capture.get(Videoio.CAP_PROP_FRAME_WIDTH));
-            System.out.println(capture.get(Videoio.CAP_PROP_FRAME_HEIGHT));
-            executor.execute(() -> {
-                SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
-                Mat frame = new Mat();
-                Mat v = new Mat();
-                long frameCount = 0;
-                while (capture.read(frame)) {
-                    frameCount++;
-                    if (frameCount % 200 == 0) {
-                        System.gc();
-                    }
-                    if (System.currentTimeMillis() - lastStat.get(videoPath) > 60 * 1000) {
-                        break;
-                    }
-                    if (frameCount % 3 != 0) {
-                        continue;
-                    }
-                    if (matchGameOver(svm, frame)) {
-                        String rank = extractRank(frame);
-                        String time = extractGameTime(frame);
-                        if (StringUtils.isNotEmpty(rank) && StringUtils.isNotEmpty(time)) {
-                            rank = rank.trim().replace(" ", "").replace("\n", "");
-                            time = time.trim().replace(" ", "").replace("\n", "");
-                            if (Pattern.matches("^第\\d{1,3}$", rank)
-                                    && Pattern.matches("((^([0-9]+[.][0-9]*))|(^\\d{1,2}))分钟", time)) {
-                                System.out.println(rank);
-                                System.out.println(time);
-                                Map<String, Object> map = new HashMap<>();
-                                map.put("rank", rank);
-                                map.put("time", time);
-                                BufferedImage image = createBufferedImage(frame);
-                                ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
-                                try {
-                                    ImageIO.write(image, "png", baos);//写入流中
-                                } catch (IOException e) {
-                                    e.printStackTrace();
-                                }
-                                byte[] bytes = baos.toByteArray();//转换成字节
-                                BASE64Encoder encoder = new BASE64Encoder();
-                                String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
-                                png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
-                                map.put("frame", "data:image/png;base64," + png_base64);
-                                resultMap.put(videoPath, map);
-                                break;
-                            }
-                        }
-                    }
-                    System.out.println(frameCount + " frame processed");
+        executor.execute(() -> {
+            try {
+                Map<String, String> map = videoProcessTool.processVideo(videoPath, 0);
+                if (map != null) {
+                    resultMap.put(videoPath, map);
                 }
-                capture.release();
-                frame.release();
-                v.release();
-                System.gc();
-                processing.remove(videoPath);
-            });
-            return true;
-        }
-        return false;
+            } catch (FrameGrabber.Exception e) {
+                e.printStackTrace();
+            }
+            processing.remove(videoPath);
+        });
+        return true;
     }
 
     @Override
@@ -155,371 +59,30 @@ public class VideoRecognitionServiceImpl implements VideoRecognitionService {
         if (playerInfo.getStatusFlag() > AppConstant.PlayerStatus.END) {
             return;
         }
-        VideoCapture capture = new VideoCapture();
-        if (capture.open(playerInfo.getVideo())) {
-            System.out.println(capture.get(Videoio.CAP_PROP_FRAME_WIDTH));
-            System.out.println(capture.get(Videoio.CAP_PROP_FRAME_HEIGHT));
-            executor.execute(() -> {
-                try {
-                    SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
-                    Mat frame = new Mat();
-                    Mat v = new Mat();
-                    long frameCount = 0;
-                    while (capture.read(frame)) {
-                        frameCount++;
-                        if (frameCount % 200 == 0) {
-                            System.gc();
-                        }
-                        if (frameCount % 3 != 0) {
-                            continue;
-                        }
-                        if (matchGameOver(svm, frame)) {
-                            String rank = extractRank(frame);
-                            String time = extractGameTime(frame);
-                            if (StringUtils.isEmpty(rank) || StringUtils.isEmpty(time)) {
-                                continue;
-                            }
-                            rank = rank.trim().replace(" ", "").replace("\n", "");
-                            time = time.trim().replace(" ", "").replace("\n", "");
-                            if (!Pattern.matches("^第\\d{1,3}$", rank)
-                                    || !Pattern.matches("((^([0-9]+[.][0-9]*))|(^\\d{1,2}))分钟", time)) {
-                                continue;
-                            }
-                            System.out.println(rank);
-                            System.out.println(time);
-                            Map<String, Object> map = new HashMap<>();
-                            map.put("rank", rank);
-                            map.put("time", time);
-                            String url = uploadImage(frame);
-                            playerInfo.setImage(url);
-                            playerInfo.setRanking(Integer.valueOf(rank.replace("第", "")));
-                            playerInfo.setLiveTime(time);
-                            playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
-                            break;
-                        }
-                        System.out.println(frameCount + " frame processed");
-                    }
-                    capture.release();
-                    frame.release();
-                    v.release();
-                    System.gc();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                if (!playerInfo.getStatusFlag().equals(AppConstant.PlayerStatus.PROCESSED)) {
-                    playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
-                }
+        executor.execute(() -> {
+            try {
                 playerInfoService.updatePlayerInfo(playerInfo);
-            });
-        } else {
-            playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
-            playerInfoService.updatePlayerInfo(playerInfo);
-        }
-    }
-
-    @Override
-    public boolean matchGameOver(SVM svm, Mat inputImage) {
-        if (inputImage.cols() < inputImage.rows()) {
-            rotate(inputImage, inputImage, ROTATE_90_COUNTERCLOCKWISE);
-        }
-        Mat v = new Mat();
-        removeBlackBar(inputImage, inputImage);
-        resize(inputImage, v, new Size(854, 480));
-        Mat p = v.reshape(1, 1);
-        p.convertTo(p, CV_32FC1);
-        float res = svm.predict(p);
-        return res == 1;
-    }
-
-    @Override
-    public String extractRank(Mat inputImage) {
-        String result = null;
-        int m = inputImage.rows();
-        int n = inputImage.cols();
-        inputImage = inputImage.rowRange(0, (int) (m * 0.5)).colRange((int) (n * 0.5), n);
-
-        Mat resultGray = new Mat(inputImage.rows(), inputImage.cols(), CV_8U, new Scalar(0));
-        Mat resultColor = new Mat(inputImage.rows(), inputImage.cols(), CV_8UC3, new Scalar(255, 255, 255));
-        HSVFilter(inputImage, resultGray, resultColor, 25, 65, 40, 255, 130, 255);
-        imshow("gray", resultGray);
-
-        int erosion_size = m / 400;
-        erode(resultGray, resultGray, erosion_size);
-
-        int dilation_size = m / 400 * 4;
-        dilate(resultGray, resultGray, dilation_size);
-
-        List<MatOfPoint> contours = new ArrayList<>();
-        Mat hierarchy = new Mat();
-        findContours(resultGray, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
-        Rect textRect = new Rect();
-        for (int i = 0; i < contours.size(); i++) {
-            Rect rect = boundingRect(contours.get(i));
-            if (rect.area() > textRect.area()) {
-                textRect = rect;
-            }
-        }
-        if (textRect.width > 0 && textRect.height > 0) {
-            Mat textImg = inputImage.rowRange(textRect.y, textRect.y + textRect.height).colRange(textRect.x, textRect.x + textRect.width);
-            Mat mat1 = new Mat(textImg.rows(), textImg.cols(), CV_8UC1);
-            for (int i = 0; i < textImg.rows(); i++) {
-                for (int j = 0; j < textImg.cols(); j++) {
-                    double s = (textImg.get(i, j)[1] + textImg.get(i, j)[2]) / 2;
-                    mat1.put(i, j, s > 220 ? s : 0);
+                Map<String, String> map = videoProcessTool.processVideo(playerInfo.getVideo(), 0);
+                if (map != null) {
+                    playerInfo.setImage(map.get("image"));
+                    playerInfo.setRanking(Integer.valueOf(map.get("rank").replace("第", "")));
+                    playerInfo.setLiveTime(map.get("time"));
+                    playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
+                } else {
+                    playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
                 }
+            } catch (FrameGrabber.Exception e) {
+                e.printStackTrace();
+                playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
             }
-            imshow("text", textImg);
-            medianBlur(mat1, mat1, 3);
-            imshow("mat1", mat1);
-            for (MatOfPoint contour : contours) {
-                Rect rect = boundingRect(contour);
-                rectangle(inputImage, rect, new Scalar(0, 0, 255), 1);
-            }
-            rectangle(inputImage, textRect, new Scalar(0, 255, 0), 2);
-            imshow("inputImage", inputImage);
-            result = doOCR(mat1);
-            textImg.release();
-            mat1.release();
-        }
-        if (DEBUG) {
-            waitKey(0);
-        }
-        inputImage.release();
-        resultGray.release();
-        resultColor.release();
-
-        System.gc();
-        return result;
-    }
-
-    @Override
-    public String extractGameTime(Mat inputImage) {
-        String result = null;
-        int m = inputImage.rows();
-        int n = inputImage.cols();
-        inputImage = inputImage.rowRange((int) (m * 0.5), (int) (m * 0.8)).colRange((int) (n * 0.5), n);
-        Mat resultGray = new Mat(inputImage.rows(), inputImage.cols(), CV_8U, new Scalar(0));
-        Mat resultColor = new Mat(inputImage.rows(), inputImage.cols(), CV_8UC3, new Scalar(255, 255, 255));
-        HSVFilter(inputImage, resultGray, resultColor, 15, 28, 80, 255, 80, 255);
-        imshow("gray", resultGray);
-
-        int dilation_size = resultGray.rows() / 120 * 3;
-        dilate(resultGray, resultGray, dilation_size);
-
-        int erosion_size = resultGray.rows() / 120 * 3;
-        erode(resultGray, resultGray, erosion_size);
-
-        dilate(resultGray, resultGray, dilation_size);
-
-        List<MatOfPoint> contours = new ArrayList<>();
-        Mat hierarchy = new Mat();
-        findContours(resultGray, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
-        Rect textRect = new Rect();
-        for (int i = 0; i < contours.size(); i++) {
-            Rect rect = boundingRect(contours.get(i));
-            if (rect.area() > textRect.area() && rect.height < inputImage.rows() / 3) {
-                textRect = rect;
-            }
-        }
-        if (textRect.width > 0 && textRect.height > 0) {
-            Mat textImg = inputImage.rowRange(textRect.y, textRect.y + textRect.height).colRange(textRect.x, textRect.x + textRect.width);
-            textImg.convertTo(textImg, CV_8UC3);
-            Mat imageBf = new Mat();
-            bilateralFilter(textImg, imageBf, 3, 3, 2);//双边滤波
-            Mat imageEnhance = new Mat();
-            Mat kernel = new Mat(3, 3, CV_32F);
-            kernel.put(0, 0, 0);
-            kernel.put(0, 1, -1);
-            kernel.put(0, 2, 0);
-            kernel.put(1, 0, 0);
-            kernel.put(1, 1, 4);
-            kernel.put(1, 2, 0);
-            kernel.put(2, 0, 0);
-            kernel.put(2, 1, -1);
-            kernel.put(2, 2, 0);
-            filter2D(imageBf, imageEnhance, CV_8UC3, kernel);
-            imshow("text", textImg);
-            imshow("imageBf", imageBf);
-            imshow("imageEnhance", imageEnhance);
-            cvtColor(textImg, textImg, COLOR_BGR2GRAY);
-            textImg.convertTo(textImg, CV_8UC1);
-            for (MatOfPoint contour : contours) {
-                Rect rect = boundingRect(contour);
-                rectangle(inputImage, rect, new Scalar(0, 0, 255), 1);
-            }
-            rectangle(inputImage, textRect, new Scalar(0, 255, 0), 1);
-            imshow("inputImage", inputImage);
-
-            result = doOCR(textImg);
-            imageBf.release();
-            imageEnhance.release();
-            textImg.release();
-        }
-        if (DEBUG) {
-            waitKey(0);
-        }
-        inputImage.release();
-        resultGray.release();
-        resultColor.release();
-
-        System.gc();
-        return result;
+            playerInfoService.updatePlayerInfo(playerInfo);
+        });
     }
 
 
     @Override
-    public Map<String, Object> stat(String videoPath) {
+    public Map<String, String> stat(String videoPath) {
         lastStat.put(videoPath, System.currentTimeMillis());
         return resultMap.get(videoPath);
     }
-
-    private void dilate(Mat src, Mat dst, int dilation_size) {
-        Mat dilationElement = getStructuringElement(MORPH_ELLIPSE,
-                new Size(2 * dilation_size + 1, 2 * dilation_size + 1),
-                new Point(dilation_size, dilation_size));
-        Imgproc.dilate(src, dst, dilationElement);
-        imshow("dilate", dst);
-    }
-
-    private void erode(Mat src, Mat dst, int erosion_size) {
-        Mat erodeElement = getStructuringElement(MORPH_RECT,
-                new Size(2 * erosion_size + 1, 2 * erosion_size + 1),
-                new Point(erosion_size, erosion_size));
-        Imgproc.erode(src, dst, erodeElement);
-        imshow("erode", dst);
-    }
-
-    private BufferedImage createBufferedImage(Mat mat) {
-        MatOfByte mob = new MatOfByte();
-        imencode(".jpg", mat, mob);
-        byte ba[] = mob.toArray();
-        BufferedImage bi = null;
-        try {
-            bi = ImageIO.read(new ByteArrayInputStream(ba));
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return bi;
-    }
-
-    private void HSVFilter(Mat inputImage, Mat resultGray, Mat resultColor, int h_min, int h_max, int s_min, int s_max, int v_min, int v_max) {
-        Mat hsvImage = new Mat();
-        blur(inputImage, hsvImage, new Size(3, 3));
-        cvtColor(hsvImage, hsvImage, COLOR_BGR2HSV);
-        double H = 0.0, S = 0.0, V = 0.0;
-        for (int i = 0; i < hsvImage.rows(); i++) {
-            for (int j = 0; j < hsvImage.cols(); j++) {
-                H = hsvImage.get(i, j)[0];
-                S = hsvImage.get(i, j)[1];
-                V = hsvImage.get(i, j)[2];
-
-                if ((H >= h_min && H <= h_max)
-                        && (S >= s_min && S <= s_max)
-                        && (V >= v_min && V <= v_max)) {
-                    resultGray.put(i, j, 255d);
-                    resultColor.put(i, j, inputImage.get(i, j));
-                }
-            }
-        }
-        hsvImage.release();
-    }
-
-    private String doOCR(Mat img) {
-        BufferedImage bi = createBufferedImage(img);
-        ITesseract instance = new Tesseract();
-        instance.setDatapath(GetResource.class.getClassLoader().getResource("trainneddata").getPath());
-        instance.setPageSegMode(7);
-        instance.setLanguage("pubg");
-        try {
-            String result = instance.doOCR(bi);
-            if (StringUtils.isNotEmpty(result)) {
-                System.out.println(result);
-                return result;
-            }
-        } catch (TesseractException e) {
-            System.err.println(e.getMessage());
-        }
-        return null;
-    }
-
-    private void imshow(String name, Mat img) {
-        if (DEBUG) {
-            Mat copy = new Mat();
-            img.copyTo(copy);
-            HighGui.imshow(name, copy);
-        }
-    }
-
-    private void removeBlackBar(Mat src, Mat dst) {
-        int[] top = new int[20];
-        int[] bottom = new int[20];
-        int[] left = new int[20];
-        int[] right = new int[20];
-        int rowStep = (int) (src.rows() * 0.4 / 20);
-        int colStep = (int) (src.cols() * 0.4 / 20);
-        int r = (int) (src.rows() * 0.3);
-        for (int i = 0; i < 20; i++) {
-            for (int c = 2; c + 2 < src.cols(); c++) {
-                double B = (src.get(r, c - 2)[0] + src.get(r, c - 1)[0] + src.get(r, c)[0] + src.get(r, c + 1)[0] + src.get(r, c + 2)[0]) / 3f;
-                double G = (src.get(r, c - 2)[1] + src.get(r, c - 1)[1] + src.get(r, c)[1] + src.get(r, c + 1)[1] + src.get(r, c + 2)[1]) / 3f;
-                double R = (src.get(r, c - 2)[2] + src.get(r, c - 1)[2] + src.get(r, c)[2] + src.get(r, c + 1)[2] + src.get(r, c + 2)[2]) / 3f;
-                if (B > 5 && G > 5 && R > 5) {
-                    left[i] = c;
-                    break;
-                }
-            }
-            for (int c = src.cols() - 3; c - 2 >= 0; c--) {
-                double B = (src.get(r, c - 2)[0] + src.get(r, c - 1)[0] + src.get(r, c)[0] + src.get(r, c + 1)[0] + src.get(r, c + 2)[0]) / 3f;
-                double G = (src.get(r, c - 2)[1] + src.get(r, c - 1)[1] + src.get(r, c)[1] + src.get(r, c + 1)[1] + src.get(r, c + 2)[1]) / 3f;
-                double R = (src.get(r, c - 2)[2] + src.get(r, c - 1)[2] + src.get(r, c)[2] + src.get(r, c + 1)[2] + src.get(r, c + 2)[2]) / 3f;
-                if (B > 5 && G > 5 && R > 5) {
-                    right[i] = c;
-                    break;
-                }
-            }
-            r += rowStep;
-        }
-        int c = (int) (src.cols() * 0.3);
-        for (int i = 0; i < 20; i++) {
-            for (r = 2; r + 2 < src.rows(); r++) {
-                double B = (src.get(r, c - 2)[0] + src.get(r, c - 1)[0] + src.get(r, c)[0] + src.get(r, c + 1)[0] + src.get(r, c + 2)[0]) / 3f;
-                double G = (src.get(r, c - 2)[1] + src.get(r, c - 1)[1] + src.get(r, c)[1] + src.get(r, c + 1)[1] + src.get(r, c + 2)[1]) / 3f;
-                double R = (src.get(r, c - 2)[2] + src.get(r, c - 1)[2] + src.get(r, c)[2] + src.get(r, c + 1)[2] + src.get(r, c + 2)[2]) / 3f;
-                if (B > 5 && G > 5 && R > 5) {
-                    top[i] = r;
-                    break;
-                }
-            }
-            for (r = src.rows() - 3; r - 2 >= 0; r--) {
-                double B = (src.get(r, c - 2)[0] + src.get(r, c - 1)[0] + src.get(r, c)[0] + src.get(r, c + 1)[0] + src.get(r, c + 2)[0]) / 3f;
-                double G = (src.get(r, c - 2)[1] + src.get(r, c - 1)[1] + src.get(r, c)[1] + src.get(r, c + 1)[1] + src.get(r, c + 2)[1]) / 3f;
-                double R = (src.get(r, c - 2)[2] + src.get(r, c - 1)[2] + src.get(r, c)[2] + src.get(r, c + 1)[2] + src.get(r, c + 2)[2]) / 3f;
-                if (B > 5 && G > 5 && R > 5) {
-                    bottom[i] = r;
-                    break;
-                }
-            }
-            c += colStep;
-        }
-        int offsetTop = (int) Math.max(Arrays.stream(top).average().getAsDouble() - 2, 0);
-        int offsetBottom = (int) Math.min(Arrays.stream(bottom).average().getAsDouble() + 2, src.rows() - 1);
-        int offsetLeft = (int) Math.max(Arrays.stream(left).average().getAsDouble() - 2, 0);
-        int offsetRight = (int) Math.min(Arrays.stream(right).average().getAsDouble() + 2, src.cols() - 1);
-        new Mat(src, new Rect(new Point(offsetLeft, offsetTop), new Point(offsetRight, offsetBottom))).copyTo(dst);
-    }
-
-    private String uploadImage(Mat frame) {
-        try {
-            BufferedImage image = createBufferedImage(frame);
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
-            ImageIO.write(image, "png", baos);//写入流中
-            byte[] bytes = baos.toByteArray();//转换成字节
-            InputStream in = new ByteArrayInputStream(bytes);
-            String path = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), UUID.randomUUID().toString());
-            return ossFileService.upload(in, path);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
 }

+ 339 - 0
src/main/java/com/izouma/awesomeadmin/util/VideoProcessTool.java

@@ -0,0 +1,339 @@
+package com.izouma.awesomeadmin.util;
+
+import com.izouma.awesomeadmin.service.OSSFileService;
+import org.apache.commons.lang3.StringUtils;
+import org.bytedeco.javacpp.indexer.UByteRawIndexer;
+import org.bytedeco.javacpp.opencv_imgproc;
+import org.bytedeco.javacpp.opencv_ml;
+import org.bytedeco.javacpp.tesseract;
+import org.bytedeco.javacv.FFmpegFrameGrabber;
+import org.bytedeco.javacv.Frame;
+import org.bytedeco.javacv.FrameGrabber;
+import org.bytedeco.javacv.OpenCVFrameConverter;
+import org.hibernate.validator.internal.util.privilegedactions.GetResource;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+import static org.bytedeco.javacpp.lept.pixRead;
+import static org.bytedeco.javacpp.opencv_core.*;
+import static org.bytedeco.javacpp.opencv_imgcodecs.imencode;
+import static org.bytedeco.javacpp.opencv_imgcodecs.imwrite;
+import static org.bytedeco.javacpp.opencv_imgproc.*;
+import static org.bytedeco.javacpp.opencv_ml.SVM;
+import static org.bytedeco.javacpp.tesseract.PSM_SINGLE_LINE;
+
+public class VideoProcessTool {
+    private OSSFileService ossFileService = new OSSFileService();
+
+    public Map<String, String> processVideo(String path, int frameSkip) throws FrameGrabber.Exception {
+        SVM svm = opencv_ml.SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
+        Map<String, String> map = new HashMap<>();
+        OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat();
+        long frameCount = 0;
+        FrameGrabber videoGrabber = new FFmpegFrameGrabber(path);
+        videoGrabber.start();
+        Frame vFrame;
+        do {
+            vFrame = videoGrabber.grabFrame();
+            if (vFrame != null) {
+                frameCount++;
+                if (frameCount % 200 == 0) {
+                    System.gc();
+                }
+                if (frameSkip > 0 && frameCount % frameSkip != 0) {
+                    continue;
+                }
+                Mat frame = converterToMat.convert(vFrame);
+                if (matchGameOver(svm, frame)) {
+                    String rank = extractRank(frame);
+                    String time = extractGameTime(frame);
+                    if (StringUtils.isEmpty(rank) || StringUtils.isEmpty(time)) {
+                        continue;
+                    }
+                    rank = rank.trim().replace(" ", "").replace("\n", "");
+                    time = time.trim().replace(" ", "").replace("\n", "");
+                    if (!Pattern.matches("^第\\d{1,3}$", rank)
+                            || !Pattern.matches("((^([0-9]+[.][0-9]*))|(^\\d{1,2}))分钟", time)) {
+                        continue;
+                    }
+                    map.put("rank", rank);
+                    map.put("time", time);
+                    map.put("image", uploadImage(frame));
+                    System.out.println(map);
+                    break;
+                }
+                frame.release();
+                System.out.println(frameCount + " frame processed");
+            }
+        } while (vFrame != null);
+        videoGrabber.stop();
+        videoGrabber.release();
+        svm.deallocate();
+        System.gc();
+        return map;
+    }
+
+    public boolean matchGameOver(opencv_ml.SVM svm, Mat inputImage) {
+        Mat rotated = new Mat();
+        if (inputImage.cols() < inputImage.rows()) {
+            rotate(inputImage, rotated, ROTATE_90_COUNTERCLOCKWISE);
+        } else {
+            inputImage.copyTo(rotated);
+        }
+        Mat resized = new Mat();
+        Mat noBlackBar = new Mat();
+        removeBlackBar(rotated, noBlackBar);
+        resize(noBlackBar, resized, new Size(854, 480));
+        Mat reshaped = resized.reshape(1, 1);
+        Mat toPredict = new Mat();
+        reshaped.convertTo(toPredict, CV_32F);
+        float res = svm.predict(toPredict);
+
+        rotated.release();
+        resized.release();
+        noBlackBar.release();
+        reshaped.release();
+        toPredict.release();
+        return res == 1;
+    }
+
+    public String extractRank(Mat inputImage) {
+        String result = null;
+        int m = inputImage.rows();
+        int n = inputImage.cols();
+        Mat roi = inputImage.rowRange(0, (int) (m * 0.5)).colRange((int) (n * 0.5), n);
+
+        Mat resultGray = new Mat(roi.rows(), roi.cols(), CV_8U, new Scalar(0));
+        HSVFilter(roi, resultGray, 25, 65, 40, 255, 130, 255);
+
+        Mat eroded = new Mat();
+        int erosion_size = m / 400;
+        erode(resultGray, eroded, erosion_size);
+        resultGray.release();
+
+        Mat dilated = new Mat();
+        int dilation_size = m / 400 * 4;
+        dilate(eroded, dilated, dilation_size);
+
+        MatVector contours = new MatVector();
+        Mat hierarchy = new Mat();
+        findContours(dilated, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
+        eroded.release();
+        dilated.release();
+        hierarchy.release();
+
+        Rect textRect = new Rect();
+        for (int i = 0; i < contours.size(); i++) {
+            Rect rect = boundingRect(contours.get(i));
+            if (rect.area() > textRect.area()) {
+                textRect = rect;
+            }
+        }
+        if (textRect.width() > 0 && textRect.height() > 0) {
+            Mat text = roi.rowRange(textRect.y(), textRect.y() + textRect.height()).colRange(textRect.x(), textRect.x() + textRect.width());
+            Mat textBin = new Mat(text.rows(), text.cols(), CV_8UC1);
+            UByteRawIndexer textIndexer = text.createIndexer();
+            UByteRawIndexer textBinIndexer = textBin.createIndexer();
+            for (int i = 0; i < text.rows(); i++) {
+                for (int j = 0; j < text.cols(); j++) {
+                    int s = (textIndexer.get(i, j, 1) + textIndexer.get(i, j, 2)) / 2;
+                    textBinIndexer.put(i, j, s > 220 ? s : 0);
+                }
+            }
+            textIndexer.release();
+            textBinIndexer.release();
+            text.release();
+            Mat blurred = new Mat();
+            medianBlur(textBin, blurred, 3);
+            textBin.release();
+
+            for (int i = 0; i < contours.size(); i++) {
+                Rect rect = boundingRect(contours.get(i));
+                rectangle(roi, rect, new Scalar(0, 0, 255, 0), 2, LINE_AA, 0);
+            }
+            rectangle(roi, textRect, new Scalar(0, 255, 0, 0), 2, LINE_AA, 0);
+            result = doOCR(blurred);
+            blurred.release();
+        }
+        roi.release();
+
+        return result;
+    }
+
+    public String extractGameTime(Mat inputImage) {
+        String result = null;
+        int m = inputImage.rows();
+        int n = inputImage.cols();
+        inputImage = inputImage.rowRange((int) (m * 0.5), (int) (m * 0.8)).colRange((int) (n * 0.5), n);
+        Mat resultGray = new Mat(inputImage.rows(), inputImage.cols(), CV_8U, new Scalar(0));
+        HSVFilter(inputImage, resultGray, 15, 28, 80, 255, 80, 255);
+
+        Mat dilate1 = new Mat();
+        int dilation_size = resultGray.rows() / 120 * 3;
+        dilate(resultGray, dilate1, dilation_size);
+
+        Mat erode = new Mat();
+        int erosion_size = resultGray.rows() / 120 * 3;
+        erode(dilate1, erode, erosion_size);
+
+        Mat dilate2 = new Mat();
+        dilate(erode, dilate2, dilation_size);
+
+        dilate1.release();
+        erode.release();
+        resultGray.release();
+        resultGray = new Mat();
+        dilate2.copyTo(resultGray);
+        dilate2.release();
+
+        MatVector contours = new MatVector();
+        Mat hierarchy = new Mat();
+        findContours(resultGray, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
+        hierarchy.release();
+        Rect textRect = new Rect();
+        for (int i = 0; i < contours.size(); i++) {
+            Rect rect = boundingRect(contours.get(i));
+            if (rect.area() > textRect.area() && rect.height() < inputImage.rows() / 3) {
+                textRect = rect;
+            }
+        }
+        if (textRect.width() > 0 && textRect.height() > 0) {
+            Mat roi = inputImage.rowRange(textRect.y(), textRect.y() + textRect.height()).colRange(textRect.x(), textRect.x() + textRect.width());
+            Mat textImg = new Mat();
+            roi.convertTo(textImg, CV_8UC3);
+            roi.release();
+            cvtColor(textImg, textImg, COLOR_BGR2GRAY);
+            Mat textGray = new Mat();
+            textImg.convertTo(textGray, CV_8UC1);
+            imwrite("/Users/drew/Desktop/text.jpg", textImg);
+            textImg.release();
+            for (int i = 0; i < contours.size(); i++) {
+                Rect rect = boundingRect(contours.get(i));
+                rectangle(inputImage, rect, new Scalar(0, 0, 255, 0), 2, LINE_AA, 0);
+            }
+            rectangle(inputImage, textRect, new Scalar(0, 255, 0, 0), 2, LINE_AA, 0);
+            result = doOCR(textGray);
+            textGray.release();
+        }
+        resultGray.release();
+        return result;
+    }
+
+    private void dilate(Mat src, Mat dst, int dilation_size) {
+        Mat dilationElement = getStructuringElement(MORPH_ELLIPSE,
+                new Size(2 * dilation_size + 1, 2 * dilation_size + 1),
+                new Point(dilation_size, dilation_size));
+        opencv_imgproc.dilate(src, dst, dilationElement);
+        dilationElement.release();
+    }
+
+    private void erode(Mat src, Mat dst, int erosion_size) {
+        Mat erodeElement = getStructuringElement(MORPH_RECT,
+                new Size(2 * erosion_size + 1, 2 * erosion_size + 1),
+                new Point(erosion_size, erosion_size));
+        opencv_imgproc.erode(src, dst, erodeElement);
+        erodeElement.release();
+    }
+
+    private void HSVFilter(Mat inputImage, Mat resultGray, int h_min, int h_max, int s_min, int s_max, int v_min, int v_max) {
+        Mat hsvImage = new Mat();
+        Mat blurred = new Mat();
+        blur(inputImage, blurred, new Size(3, 3));
+        cvtColor(blurred, hsvImage, COLOR_BGR2HSV);
+        double H, S, V;
+        UByteRawIndexer hsvIndexer = hsvImage.createIndexer();
+        UByteRawIndexer resultGrayIndexer = resultGray.createIndexer();
+        for (int i = 0; i < hsvImage.rows(); i++) {
+            for (int j = 0; j < hsvImage.cols(); j++) {
+                H = hsvIndexer.get(i, j, 0);
+                S = hsvIndexer.get(i, j, 1);
+                V = hsvIndexer.get(i, j, 2);
+
+                if ((H >= h_min && H <= h_max)
+                        && (S >= s_min && S <= s_max)
+                        && (V >= v_min && V <= v_max)) {
+                    resultGrayIndexer.put(i, j, 255);
+                }
+            }
+        }
+        hsvImage.release();
+        blurred.release();
+        hsvIndexer.release();
+        resultGrayIndexer.release();
+    }
+
+    private String doOCR(Mat img) {
+        imwrite("/Users/drew/Desktop/text.jpg", img);
+        cvtColor(img, img, COLOR_GRAY2RGBA, 4);
+        final tesseract.TessBaseAPI baseApi = new tesseract.TessBaseAPI();
+        baseApi.Init(GetResource.class.getClassLoader().getResource("trainneddata").getPath(), "pubg");
+        baseApi.SetPageSegMode(PSM_SINGLE_LINE);
+        // Ensure that text is recognized.
+        // baseApi.SetImage(pixReadMem(img.data(), img.elemSize()));
+        baseApi.SetImage(pixRead("/Users/drew/Desktop/text.jpg"));
+        String recognizedText = baseApi.GetUTF8Text().getString();
+        return recognizedText;
+    }
+
+    private void removeBlackBar(Mat src, Mat dst) {
+        Mat gray = new Mat();
+        cvtColor(src, gray, COLOR_BGR2GRAY);
+        Mat thres = new Mat();
+        threshold(gray, thres, 2, 255, THRESH_BINARY);
+        MatVector contours = new MatVector();
+        findContours(thres, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
+        Rect rect = boundingRect(contours.get(0));
+        for (int i = 1; i < contours.size(); i++) {
+            Rect r = boundingRect(contours.get(i));
+            if (r.area() > rect.area()) {
+                rect.deallocate();
+                rect = r;
+            }
+        }
+        src.colRange(rect.x(), rect.x() + rect.width()).rowRange(rect.y(), rect.y() + rect.height()).copyTo(dst);
+        gray.release();
+        thres.release();
+        contours.deallocate();
+        rect.deallocate();
+    }
+
+    public BufferedImage createBufferedImage(Mat mat) {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(mat.cols() * mat.rows());
+        imencode(".jpg", mat, byteBuffer);
+        byte ba[] = byteBuffer.array();
+        BufferedImage bi = null;
+        try {
+            bi = ImageIO.read(new ByteArrayInputStream(ba));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return bi;
+    }
+
+    public String uploadImage(Mat frame) {
+        try {
+            BufferedImage image = createBufferedImage(frame);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
+            ImageIO.write(image, "png", baos);//写入流中
+            byte[] bytes = baos.toByteArray();//转换成字节
+            InputStream in = new ByteArrayInputStream(bytes);
+            String path = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), UUID.randomUUID().toString());
+            return ossFileService.upload(in, path);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 71 - 42
src/main/java/com/izouma/awesomeadmin/web/PlayerInfoController.java

@@ -6,6 +6,7 @@ import com.izouma.awesomeadmin.dto.Result;
 import com.izouma.awesomeadmin.model.PlayerInfo;
 import com.izouma.awesomeadmin.service.OSSFileService;
 import com.izouma.awesomeadmin.service.PlayerInfoService;
+import com.izouma.awesomeadmin.service.VideoRecognitionService;
 import com.izouma.awesomeadmin.util.ExportExcelUtil;
 import org.apache.shiro.authz.annotation.RequiresAuthentication;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +23,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -34,9 +34,11 @@ import java.util.*;
 public class PlayerInfoController {
 
     @Autowired
-    private PlayerInfoService playerInfoService;
+    private PlayerInfoService       playerInfoService;
     @Autowired
-    private OSSFileService    OSSFileService;
+    private OSSFileService          OSSFileService;
+    @Autowired
+    private VideoRecognitionService videoRecognitionService;
 
     /**
      * <p>获取全部记录。</p>
@@ -279,57 +281,84 @@ public class PlayerInfoController {
             PlayerInfo playerInfo = new PlayerInfo();
             playerInfo.setId(id);
             MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
-            Iterator it = multiRequest.getFileNames();
-            List<String> paths = new ArrayList<>();
-            String video = null;
-            while (it.hasNext()) {
-                MultipartFile file = multiRequest.getFile(it.next().toString());
-                if (file == null) continue;
+
+            MultipartFile videoFile = multiRequest.getFile("video");
+            MultipartFile screenshotFile = multiRequest.getFile("screenshot");
+            if (videoFile != null) {
                 try {
-                    if ("video".equalsIgnoreCase(file.getName())) {
-                        Random random = new Random();
-                        StringBuilder randomCode = new StringBuilder();
-                        for (int i = 0; i < 8; i++) {
-                            randomCode.append(Integer.toString(random.nextInt(36), 36));
-                        }
-                        String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
-                        video = String.format("/var/videos/%s-%s%s", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
-                        file.transferTo(new File(video));
-                        Runtime.getRuntime().exec("chmod 777 " + video);
-                        playerInfo.setVideo(video);
-                    } else if ("screenshot".equalsIgnoreCase(file.getName())) {
-                        Random random = new Random();
-                        StringBuilder randomCode = new StringBuilder();
-                        for (int i = 0; i < 8; i++) {
-                            randomCode.append(Integer.toString(random.nextInt(36), 36));
-                        }
-                        String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
-                        String fileType = file.getContentType().substring(0, file.getContentType().indexOf("/"));
-                        String uploadPath = String.format("%s/%s-%s%s", fileType, new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
-                        String screenshot = OSSFileService.upload(file.getInputStream(), uploadPath);
-                        playerInfo.setImage(screenshot);
-                    }
-                } catch (IOException e) {
+                    String fileName = genFileName(videoFile);
+                    File saveFile = new File("/var/videos", fileName);
+                    videoFile.transferTo(saveFile);
+                    Runtime.getRuntime().exec("chmod 777 " + saveFile.getAbsolutePath());
+                    playerInfo.setVideo(saveFile.getAbsolutePath());
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
-            if (rank != null && time != null) {
-                if (!"null".equals(rank) && !"null".equals(time)) {
-                    playerInfo.setRanking(Integer.valueOf(rank));
-                    playerInfo.setLiveTime(time);
-                    playerInfo.setVideo(video);
-                    playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
-                } else {
-                    playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
+            if (screenshotFile != null) {
+                try {
+                    String fileName = genFileName(screenshotFile);
+                    String uploadPath = String.format("%s/%s", "image", fileName);
+                    String screenshot = OSSFileService.upload(screenshotFile.getInputStream(), uploadPath);
+                    playerInfo.setImage(screenshot);
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
+            }
+            if (rank != null && time != null && !"null".equals(rank) && !"null".equals(time)) {
+                playerInfo.setRanking(Integer.valueOf(rank));
+                playerInfo.setLiveTime(time);
+                playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
             } else {
                 playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
             }
             playerInfoService.updatePlayerInfo(playerInfo);
-            return new Result(true, paths);
+            return new Result(true, "");
         }
         return new Result(false, "上传失败");
     }
 
+    private String genFileName(MultipartFile file) {
+        Random random = new Random();
+        StringBuilder randStr = new StringBuilder();
+        for (int i = 0; i < 8; i++) {
+            randStr.append(Integer.toString(random.nextInt(36), 36));
+        }
+        String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+        return String.format("%s-%s%s", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randStr, ext);
+    }
+
+    @RequestMapping(value = "/uploadVideo")
+    @ResponseBody
+    public Result uploadVideo(HttpServletRequest request, Integer id) {
+        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
+        if (multipartResolver.isMultipart(request)) {
+            PlayerInfo playerInfo = new PlayerInfo();
+            playerInfo.setId(id);
+            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
+            String video;
+            MultipartFile file = multiRequest.getFile("video");
+            if (file == null) return new Result(false, "");
+            try {
+                Random random = new Random();
+                StringBuilder randomCode = new StringBuilder();
+                for (int i = 0; i < 8; i++) {
+                    randomCode.append(Integer.toString(random.nextInt(36), 36));
+                }
+                String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+                video = String.format("/var/videos/%s-%s%s", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
+                file.transferTo(new File(video));
+                Runtime.getRuntime().exec("chmod 777 " + video);
+                playerInfo.setVideo(video);
+                playerInfoService.updatePlayerInfo(playerInfo);
+                playerInfo = playerInfoService.getPlayerInfoById(String.valueOf(playerInfo.getId()));
+                videoRecognitionService.start(playerInfo);
+                return new Result(true, "");
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return new Result(false, "");
+    }
 }
 

+ 1 - 1
src/main/java/com/izouma/awesomeadmin/web/VideoRecognitionController.java

@@ -27,7 +27,7 @@ public class VideoRecognitionController {
     @RequestMapping("/stat")
     @ResponseBody
     public Result stat(@RequestParam("videoPath") String videoPath) {
-        Map<String, Object> map = videoRecognitionService.stat(videoPath);
+        Map<String, String> map = videoRecognitionService.stat(videoPath);
         if (map != null) {
             return new Result(true, map);
         }

+ 0 - 60
src/test/java/RecognitionTest.java

@@ -1,60 +0,0 @@
-import com.google.zxing.common.detector.MathUtils;
-import com.izouma.awesomeadmin.service.VideoRecognitionService;
-import com.izouma.awesomeadmin.service.impl.VideoRecognitionServiceImpl;
-import org.apache.commons.lang.StringUtils;
-import org.hibernate.validator.internal.util.privilegedactions.GetResource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.opencv.core.Mat;
-import org.opencv.imgcodecs.Imgcodecs;
-import org.opencv.ml.SVM;
-import org.opencv.videoio.VideoCapture;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.support.GenericXmlContextLoader;
-import org.springframework.transaction.annotation.Transactional;
-import sun.misc.BASE64Encoder;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import static org.opencv.imgcodecs.Imgcodecs.imread;
-import static org.opencv.imgcodecs.Imgcodecs.imwrite;
-
-@RunWith(value = SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)
-@Transactional
-public class RecognitionTest {
-
-
-    @Autowired
-    private VideoRecognitionService videoRecognitionService;
-
-    @Test
-    public void testRecognition() {
-        VideoRecognitionServiceImpl.DEBUG = true;
-//        Mat img = Imgcodecs.imread("/Users/drew/Desktop/11.jpg");
-////         Mat img = Imgcodecs.imread("/Users/drew/Desktop/has/IMG_0789.png");
-//         String time = videoRecognitionService.extractGameTime(img);
-//         System.out.println("time:" + time);
-//
-//        String rank = videoRecognitionService.extractRank(img);
-//        System.out.println("rank:" + rank);
-//         SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
-//         Mat frame = imread("/Users/drew/Desktop/1.jpg");
-//         if (videoRecognitionService.matchGameOver(svm, frame)) {
-//             String rank = videoRecognitionService.extractRank(frame);
-//             String time = videoRecognitionService.extractGameTime(frame);
-//             System.out.println(rank);
-//             System.out.println(time);
-//         }
-        videoRecognitionService.start("/Users/drew/Downloads/84703-1551350776.flv");
-    }
-}

+ 65 - 0
src/test/java/VideoProcessTest.java

@@ -0,0 +1,65 @@
+import com.izouma.awesomeadmin.util.VideoProcessTool;
+import org.bytedeco.javacpp.opencv_ml;
+import org.bytedeco.javacv.FFmpegFrameGrabber;
+import org.bytedeco.javacv.FrameGrabber;
+import org.hibernate.validator.internal.util.privilegedactions.GetResource;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.GenericXmlContextLoader;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import static org.bytedeco.javacpp.opencv_core.Mat;
+import static org.bytedeco.javacpp.opencv_imgcodecs.imread;
+
+
+@RunWith(value = SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)
+@Transactional
+public class VideoProcessTest {
+
+    private VideoProcessTool videoProcessTool = new VideoProcessTool();
+
+    @Test
+    public void testVideo() {
+        try {
+            Map<String, String> result = videoProcessTool.processVideo("/Users/drew/Downloads/record1553760548328.mp4", 0);
+            System.out.println(result);
+        } catch (FrameGrabber.Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testMatch() {
+        opencv_ml.SVM svm = opencv_ml.SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
+        Mat img = imread("/Users/drew/Pictures/Screenshots/2019-03-27-04-12-40-mm7ni1ku-0001.jpg");
+        boolean b = videoProcessTool.matchGameOver(svm, img);
+        System.out.println(b);
+    }
+
+    @Test
+    public void testTime() {
+        Mat img = imread("/Users/drew/Pictures/Screenshots/record1553759305785-0001.jpg");
+        String time = videoProcessTool.extractGameTime(img);
+        System.out.println("time:" + time);
+    }
+
+    @Test
+    public void testRank() {
+        Mat img = imread("/Users/drew/Pictures/Screenshots/record1553760548328-0001.jpg");
+        String rank = videoProcessTool.extractRank(img);
+        System.out.println(videoProcessTool.uploadImage(img));
+        System.out.println("rank:" + rank);
+        try {
+            rank.getBytes("utf-8");
+            System.out.println("is utf8");
+        } catch (UnsupportedEncodingException e) {
+            System.out.println("not utf8");
+        }
+    }
+}