@@ -1,11 +1,11 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> | |||
<component name="PublishConfigData" autoUpload="Always" serverName="66" remoteFilesAllowedToDisappearOnAutoupload="false"> | |||
<component name="PublishConfigData" autoUpload="Always" remoteFilesAllowedToDisappearOnAutoupload="false"> | |||
<serverData> | |||
<paths name="66"> | |||
<serverdata> | |||
<mappings> | |||
<mapping deploy="/home/DATA/chenyukun/algSch" local="$PROJECT_DIR$" web="/" /> | |||
<mapping deploy="/home/DATA/prod/algSch" local="$PROJECT_DIR$" web="/" /> | |||
<mapping local="" /> | |||
</mappings> | |||
</serverdata> | |||
@@ -25,6 +25,20 @@ | |||
</mappings> | |||
</serverdata> | |||
</paths> | |||
<paths name="thsw2@192.168.10.66:22"> | |||
<serverdata> | |||
<mappings> | |||
<mapping local="$PROJECT_DIR$" web="/" /> | |||
</mappings> | |||
</serverdata> | |||
</paths> | |||
<paths name="thsw2@212.129.223.66:6500"> | |||
<serverdata> | |||
<mappings> | |||
<mapping local="$PROJECT_DIR$" web="/" /> | |||
</mappings> | |||
</serverdata> | |||
</paths> | |||
</serverData> | |||
<option name="myAutoUpload" value="ALWAYS" /> | |||
</component> |
@@ -0,0 +1,10 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> | |||
<component name="RunConfigurationProducerService"> | |||
<option name="ignoredProducers"> | |||
<set> | |||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> | |||
</set> | |||
</option> | |||
</component> | |||
</project> |
@@ -4,12 +4,29 @@ | |||
<option name="autoReloadType" value="SELECTIVE" /> | |||
</component> | |||
<component name="ChangeListManager"> | |||
<list default="true" id="4f7dccd9-8f92-4a6e-90cc-33890d102263" name="Changes" comment=""> | |||
<list default="true" id="4f7dccd9-8f92-4a6e-90cc-33890d102263" name="Changes" comment="Changes"> | |||
<change afterPath="$PROJECT_DIR$/.idea/runConfigurations.xml" afterDir="false" /> | |||
<change afterPath="$PROJECT_DIR$/test/ffmpeg11/ffmpeg33.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/.idea/deployment.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/deployment.xml" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/config/ModelConfig.py" beforeDir="false" afterPath="$PROJECT_DIR$/config/ModelConfig.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/enums/ModelTypeEnum.py" beforeDir="false" afterPath="$PROJECT_DIR$/enums/ModelTypeEnum.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/concurrency/MessagePollingThread.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/MessagePollingThread.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/dsp_application.yml" beforeDir="false" afterPath="$PROJECT_DIR$/dsp_application.yml" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/dsp_master.py" beforeDir="false" afterPath="$PROJECT_DIR$/dsp_master.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/service/Dispatcher.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/Dispatcher.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/AI.jpg" beforeDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/ORB算法.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/ORB算法.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/a.jpg" beforeDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/b.jpg" beforeDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/d.jpg" beforeDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/互信息.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/互信息.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/余弦相似度计算.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/余弦相似度计算.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/视频添加图片水印1.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/视频添加图片水印1.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/视频添加文字水印.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/视频添加文字水印.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/视频添加文字水印1.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/视频添加文字水印1.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/视频添加文字水印2.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/视频添加文字水印2.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/test/视频添加文字水印3.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/视频添加文字水印3.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/util/Cv2Utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/Cv2Utils.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/util/ModelUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/ModelUtils.py" afterDir="false" /> | |||
</list> | |||
<option name="SHOW_DIALOG" value="false" /> | |||
@@ -140,7 +157,7 @@ | |||
<property name="WebServerToolWindowPanel.toolwindow.show.date" value="false" /> | |||
<property name="WebServerToolWindowPanel.toolwindow.show.permissions" value="false" /> | |||
<property name="WebServerToolWindowPanel.toolwindow.show.size" value="false" /> | |||
<property name="last_opened_file_path" value="$PROJECT_DIR$/../../code/river/river_demo" /> | |||
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> | |||
<property name="node.js.detected.package.eslint" value="true" /> | |||
<property name="node.js.detected.package.tslint" value="true" /> | |||
<property name="node.js.selected.package.eslint" value="(autodetect)" /> | |||
@@ -153,17 +170,18 @@ | |||
</component> | |||
<component name="RecentsManager"> | |||
<key name="CopyFile.RECENT_KEYS"> | |||
<recent name="D:\work\alg\tuoheng_alg\test\ffmpeg11" /> | |||
<recent name="D:\work\alg_new\tuoheng_alg\util" /> | |||
<recent name="D:\work\alg\tuoheng_alg\data" /> | |||
<recent name="D:\work\alg\tuoheng_alg\test" /> | |||
<recent name="D:\work\alg\tuoheng_alg\font" /> | |||
<recent name="D:\work\code_new\tuoheng_alg\enums" /> | |||
</key> | |||
<key name="MoveFile.RECENT_KEYS"> | |||
<recent name="D:\work\alg\tuoheng_alg\test\水印" /> | |||
<recent name="D:\work\alg\tuoheng_alg\image" /> | |||
</key> | |||
</component> | |||
<component name="RunManager" selected="Python.ImageUtils"> | |||
<component name="RunManager" selected="Python.ffmpeg33"> | |||
<configuration name="ImageUtils" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> | |||
<module name="tuoheng_alg" /> | |||
<option name="INTERPRETER_OPTIONS" value="" /> | |||
@@ -230,20 +248,20 @@ | |||
<option name="INPUT_FILE" value="" /> | |||
<method v="2" /> | |||
</configuration> | |||
<configuration name="asnyc" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> | |||
<configuration name="ffmpeg33" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> | |||
<module name="tuoheng_alg" /> | |||
<option name="INTERPRETER_OPTIONS" value="" /> | |||
<option name="PARENT_ENVS" value="true" /> | |||
<envs> | |||
<env name="PYTHONUNBUFFERED" value="1" /> | |||
</envs> | |||
<option name="SDK_HOME" value="sftp://root@212.129.223.66:20653/opt/conda/bin/python3.8" /> | |||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test" /> | |||
<option name="SDK_HOME" value="$PROJECT_DIR$/../../../software/anaconda/envs/test/python.exe" /> | |||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/ffmpeg11" /> | |||
<option name="IS_MODULE_SDK" value="false" /> | |||
<option name="ADD_CONTENT_ROOTS" value="true" /> | |||
<option name="ADD_SOURCE_ROOTS" value="true" /> | |||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> | |||
<option name="SCRIPT_NAME" value="/home/DATA/chenyukun/algSch/test/asnyc.py" /> | |||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/ffmpeg11/ffmpeg33.py" /> | |||
<option name="PARAMETERS" value="" /> | |||
<option name="SHOW_COMMAND_LINE" value="false" /> | |||
<option name="EMULATE_TERMINAL" value="false" /> | |||
@@ -298,19 +316,19 @@ | |||
</configuration> | |||
<list> | |||
<item itemvalue="Python.mysqltest" /> | |||
<item itemvalue="Python.asnyc" /> | |||
<item itemvalue="Python.KafkaUtils" /> | |||
<item itemvalue="Python.KafkaUtils (1)" /> | |||
<item itemvalue="Python.producer_start" /> | |||
<item itemvalue="Python.ImageUtils" /> | |||
<item itemvalue="Python.ffmpeg33" /> | |||
</list> | |||
<recent_temporary> | |||
<list> | |||
<item itemvalue="Python.ffmpeg33" /> | |||
<item itemvalue="Python.ImageUtils" /> | |||
<item itemvalue="Python.producer_start" /> | |||
<item itemvalue="Python.KafkaUtils (1)" /> | |||
<item itemvalue="Python.KafkaUtils" /> | |||
<item itemvalue="Python.asnyc" /> | |||
</list> | |||
</recent_temporary> | |||
</component> | |||
@@ -353,6 +371,13 @@ | |||
<workItem from="1663472604061" duration="19071000" /> | |||
<workItem from="1663515200540" duration="648000" /> | |||
<workItem from="1663545195142" duration="10121000" /> | |||
<workItem from="1666136820911" duration="26264000" /> | |||
<workItem from="1666223126104" duration="11494000" /> | |||
<workItem from="1666269871579" duration="3963000" /> | |||
<workItem from="1666351797324" duration="835000" /> | |||
<workItem from="1666436589395" duration="2588000" /> | |||
<workItem from="1666568450522" duration="695000" /> | |||
<workItem from="1666658084006" duration="458000" /> | |||
</task> | |||
<servers /> | |||
</component> | |||
@@ -371,22 +396,42 @@ | |||
</option> | |||
<option name="oldMeFiltersMigrated" value="true" /> | |||
</component> | |||
<component name="XDebuggerManager"> | |||
<breakpoint-manager> | |||
<breakpoints> | |||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> | |||
<url>file://$PROJECT_DIR$/test/ffmpeg11/ffmpeg33.py</url> | |||
<line>24</line> | |||
<option name="timeStamp" value="1" /> | |||
</line-breakpoint> | |||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> | |||
<url>file://$PROJECT_DIR$/test/ffmpeg11/ffmpeg33.py</url> | |||
<line>22</line> | |||
<option name="timeStamp" value="2" /> | |||
</line-breakpoint> | |||
</breakpoints> | |||
</breakpoint-manager> | |||
</component> | |||
<component name="XSLT-Support.FileAssociations.UIState"> | |||
<expand /> | |||
<select /> | |||
</component> | |||
<component name="com.intellij.coverage.CoverageDataManagerImpl"> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$KafkaUtils__1_.coverage" NAME="KafkaUtils (1) Coverage Results" MODIFIED="1663464961001" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/util" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$cv2test1__1_.coverage" NAME="cv2test1 覆盖结果" MODIFIED="1665820653649" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$mysqltest.coverage" NAME="mysqltest Coverage Results" MODIFIED="1660868712851" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$ffmpeg33.coverage" NAME="ffmpeg33 覆盖结果" MODIFIED="1666185710677" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/ffmpeg11" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$asnyc.coverage" NAME="asnyc Coverage Results" MODIFIED="1663459033435" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$.coverage" NAME="视频添加图片水印 Coverage Results" MODIFIED="1661873949526" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$1.coverage" NAME="视频添加文字水印1 Coverage Results" MODIFIED="1663381948693" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$asnyc__1_.coverage" NAME="asnyc (1) Coverage Results" MODIFIED="1663458917599" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$producer_start.coverage" NAME="producer_start Coverage Results" MODIFIED="1663466832843" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$dsp_master.coverage" NAME="dsp_master Coverage Results" MODIFIED="1663403978477" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$producer_start.coverage" NAME="producer_start 覆盖结果" MODIFIED="1665896605019" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="/home/DATA/chenyukun/algSch/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$producer_start__1_.coverage" NAME="producer_start (1) 覆盖结果" MODIFIED="1665832569996" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$dsp_master.coverage" NAME="dsp_master 覆盖结果" MODIFIED="1665892172353" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="/home/DATA/chenyukun/algSch" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$5.coverage" NAME="视频添加图片水印5 Coverage Results" MODIFIED="1661905982885" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$KafkaUtils.coverage" NAME="KafkaUtils Coverage Results" MODIFIED="1663465345491" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/util" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$read.coverage" NAME="read Coverage Results" MODIFIED="1663640070956" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$cv2test1.coverage" NAME="cv2test1 覆盖结果" MODIFIED="1665738045603" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="/home/DATA/chenyukun/algSch/test/" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$ImageUtils.coverage" NAME="ImageUtils Coverage Results" MODIFIED="1663499421253" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/util" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$2.coverage" NAME="视频添加图片水印2 Coverage Results" MODIFIED="1661875306428" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> | |||
<SUITE FILE_PATH="coverage/tuoheng_alg$4.coverage" NAME="视频添加图片水印4 Coverage Results" MODIFIED="1661874731395" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" /> |
@@ -3,8 +3,6 @@ import os | |||
import time | |||
import copy | |||
import numpy as np | |||
from common import Constant | |||
from multiprocessing import Process, Queue | |||
from loguru import logger | |||
@@ -19,6 +17,7 @@ from util import AliyunSdk | |||
from concurrency.CommonThread import Common | |||
from concurrency.CommonProcess import CommonProcess | |||
from exception.CustomerException import ServiceException | |||
from util.ImageUtils import PictureWaterMark | |||
class IntelligentRecognitionProcess(Process): | |||
@@ -31,7 +30,7 @@ class IntelligentRecognitionProcess(Process): | |||
self.msg = cfg.get("msg") | |||
self.imageQueue = cfg.get("imageQueue") | |||
self.gpu_ids = cfg.get("gpu_ids") | |||
self.pic = cfg.get("pic") | |||
self.pic = PictureWaterMark() | |||
self.type = cfg.get("type") | |||
# 定义原视频、AI视频保存名称 | |||
random_time = TimeUtils.now_date_to_str(TimeUtils.YMDHMSF) | |||
@@ -117,10 +116,11 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): | |||
high_score_image = {} | |||
step = int(self.content["service"]["frame_step"]) | |||
concurrent_frame = 1 | |||
service_timeout = int(self.content["service"]["timeout"]) | |||
while True: | |||
end_time = time.time() | |||
create_task_time = int(end_time - start_time) | |||
if create_task_time > int(self.content["service"]["timeout"]): | |||
if create_task_time > service_timeout: | |||
logger.error("分析超时, 超时时间:{}, requestId: {}", create_task_time, self.msg.get("request_id")) | |||
raise ServiceException(ExceptionType.ANALYSE_TIMEOUT_EXCEPTION.value[0], | |||
ExceptionType.ANALYSE_TIMEOUT_EXCEPTION.value[1]) | |||
@@ -148,7 +148,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): | |||
raise ServiceException(ExceptionType.PULLSTREAM_TIMEOUT_EXCEPTION.value[0], | |||
ExceptionType.PULLSTREAM_TIMEOUT_EXCEPTION.value[1]) | |||
cv2_init_num += 1 | |||
time.sleep(0.5) | |||
time.sleep(1) | |||
cv2tool.get_video_info() | |||
cv2tool.build_pull_p() | |||
continue | |||
@@ -174,7 +174,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): | |||
start_time_2 = time.time() | |||
# time00 = time.time() | |||
# 调用AI模型 | |||
p_result, timeOut = mod.process(copy.deepcopy(frame), cv2tool.width) | |||
p_result, timeOut = mod.process(copy.deepcopy(frame), int(cv2tool.width/2)) | |||
# time11 = time.time() | |||
# if time11 - time00 > 1: | |||
# logger.info("算法模型调度时间:{}s, requestId:{}", int(time11-time00), self.msg.get("request_id")) | |||
@@ -361,7 +361,7 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess): | |||
break | |||
#time00 = time.time() | |||
# 调用AI模型 | |||
p_result, timeOut = mod.process(copy.deepcopy(frame), cv2tool.width) | |||
p_result, timeOut = mod.process(copy.deepcopy(frame), int(cv2tool.width/2)) | |||
#logger.info("算法模型调度时间:{}s, requestId:{}", time.time() - time00, self.msg.get("request_id")) | |||
# 原视频保存本地、AI视频保存本地 | |||
if self.content["video"]["video_add_water"]: |
@@ -44,6 +44,7 @@ class MessagePollingThread(Thread): | |||
customerKafkaConsumer.commit_offset(m, topics=self.cfg["topics"]) | |||
except Exception as e: | |||
logger.exception("消息监听异常: {}", e) | |||
customerKafkaConsumer = KafkaUtils.CustomerKafkaConsumer(self.cfg["content"]) | |||
time.sleep(1) | |||
def poll(self): |
@@ -1,5 +1,5 @@ | |||
dsp: | |||
active: dev | |||
active: prod12 | |||
kafka: | |||
topic: | |||
dsp-alg-online-tasks-topic: dsp-alg-online-tasks | |||
@@ -65,6 +65,26 @@ kafka: | |||
auto_offset_reset: latest | |||
enable_auto_commit: False | |||
max_poll_records: 1 | |||
test1: | |||
bootstrap_servers: ['192.168.11.242:9092'] | |||
dsp-alg-online-tasks: | |||
partition: [1] | |||
dsp-alg-offline-tasks: | |||
partition: [1] | |||
dsp-alg-task-results: | |||
partition: [1] | |||
producer: | |||
acks: -1 | |||
retries: 3 | |||
linger_ms: 50 | |||
retry_backoff_ms: 1000 | |||
max_in_flight_requests_per_connection: 5 | |||
consumer: | |||
client_id: dsp_ai_server | |||
group_id: dsp-ai-test | |||
auto_offset_reset: latest | |||
enable_auto_commit: False | |||
max_poll_records: 1 | |||
prod12: | |||
bootstrap_servers: ['101.132.127.1:19092'] | |||
dsp-alg-online-tasks: | |||
@@ -203,4 +223,4 @@ log: | |||
# # maxusage : 单个连接的最大允许复用次数(缺省值 0 或 False 代表不限制的复用).当达到最大数时,连接会自动重新连接(关闭和重新打开) | |||
# db_max_usage: 0 | |||
# # setsession : 一个可选的SQL命令列表用于准备每个会话,如["set datestyle to german", ...] | |||
# db_set_session: None | |||
# db_set_session: None |
@@ -9,4 +9,3 @@ if __name__ == '__main__': | |||
print("(♥◠‿◠)ノ゙ DSP【算法调度服务】开始启动 ლ(´ڡ`ლ)゙") | |||
# torch.multiprocessing.set_start_method('spawn') | |||
Dispatcher.DispatcherService().start_service() | |||
print("(♥◠‿◠)ノ゙ DSP【算法调度服务】启动成功 ლ(´ڡ`ლ)゙") |
@@ -14,7 +14,6 @@ from concurrency.IntelligentRecognitionProcess import OnlineIntelligentRecogniti | |||
OfflineIntelligentRecognitionProcess | |||
from concurrency.MessagePollingThread import OfflineMessagePollingThread, OnlineMessagePollingThread | |||
from util import GPUtils | |||
from util.ImageUtils import PictureWaterMark | |||
''' | |||
分发服务 | |||
@@ -39,17 +38,19 @@ class DispatcherService(): | |||
# self.photoProcesses = {} | |||
self.onlineMpt = None | |||
self.offlineMpt = None | |||
self.pic = PictureWaterMark() | |||
# 服务调用启动方法 | |||
def start_service(self): | |||
# 启动实时,离线kafka消息拉取线程 | |||
self.Kafka_message_listening() | |||
print("(♥◠‿◠)ノ゙ DSP【算法调度服务】启动成功 ლ(´ڡ`ლ)゙") | |||
# 循环消息处理 | |||
while True: | |||
time.sleep(1) | |||
# 检查任务进程运行情况,去除活动的任务 | |||
self.check_process_task() | |||
# 获取当前可用gpu使用数量 | |||
gpu_ids = GPUtils.get_gpu_ids(self.content) | |||
if gpu_ids is not None and len(gpu_ids) > 0: | |||
################## 消息驱动实时流分析进程执行 ################## | |||
@@ -133,7 +134,7 @@ class DispatcherService(): | |||
logger.warning("重复任务,请稍后再试!requestId:{}", msg.get("request_id")) | |||
return | |||
cfg = {"fbQueue": Queue(), "imageQueue": Queue(), "content": content, "msg": msg, "gpu_ids": gpu_ids, | |||
"pic": self.pic, "type": AnalysisType.ONLINE.value} | |||
"type": AnalysisType.ONLINE.value} | |||
# 创建在线识别进程并启动 | |||
oirp = OnlineIntelligentRecognitionProcess(cfg) | |||
oirp.start() | |||
@@ -163,7 +164,7 @@ class DispatcherService(): | |||
logger.warning("重复任务,请稍后再试!requestId:{}", msg.get("request_id")) | |||
return | |||
cfg = {"fbQueue": Queue(), "imageQueue": Queue(), "content": content, "msg": msg, "gpu_ids": gpu_ids, | |||
"pic": self.pic, "type": AnalysisType.OFFLINE.value} | |||
"type": AnalysisType.OFFLINE.value} | |||
# 创建在线识别进程并启动 | |||
ofirp = OfflineIntelligentRecognitionProcess(cfg) | |||
ofirp.start() |
@@ -99,7 +99,7 @@ if __name__ == '__main__': | |||
'-f', 'rawvideo', | |||
'-pix_fmt', 'bgr24', | |||
'-vcodec','rawvideo', | |||
# '-s', "{}x{}".format(int(width), int(height)), | |||
'-s', "{}x{}".format(int(width/2), int(height/2)), | |||
'-an', | |||
'-'] | |||
p = sp.Popen(command, stdout=sp.PIPE) | |||
@@ -108,7 +108,7 @@ if __name__ == '__main__': | |||
start1 = time.time() | |||
while True: | |||
start = time.time() | |||
in_bytes = p.stdout.read(width * height * 3) | |||
in_bytes = p.stdout.read(int(width * height * 3/4)) | |||
if not in_bytes: | |||
print(in_bytes) | |||
ai_video_file.release() | |||
@@ -116,18 +116,19 @@ if __name__ == '__main__': | |||
p.wait() | |||
break | |||
# 转成ndarray | |||
in_frame = (np.frombuffer(in_bytes, np.uint8).reshape([height, width, 3])) | |||
in_frame = (np.frombuffer(in_bytes, np.uint8).reshape([int(height/2), int(width/2), 3])) | |||
print("拉流时间:", time.time() - start) | |||
# frame = cv2.resize(in_frame, (1280, 720)) # 改变图片尺寸 | |||
# frame = cv2.cvtColor(in_frame, cv2.COLOR_RGB2BGR) # 转成BGR | |||
# i += 1 | |||
print(round(time.time()-start, 5)) | |||
ai_video_file.write(in_frame) | |||
if time.time() - start1 > 60: | |||
ai_video_file.release() | |||
p.stdout.close() | |||
p.wait() | |||
break | |||
# print(round(time.time()-start, 5)) | |||
# | |||
# ai_video_file.write(in_frame) | |||
# if time.time() - start1 > 60: | |||
# ai_video_file.release() | |||
# p.stdout.close() | |||
# p.wait() | |||
# break | |||
# cv2.imshow('frame', frame) | |||
# time.sleep(1111) | |||
p.kill() |
@@ -0,0 +1,78 @@ | |||
import subprocess as sp | |||
import time | |||
import cv2 | |||
import ffmpeg | |||
# 推流 | |||
import numpy as np | |||
if __name__== "__main__": | |||
# with open(str(cv2.__file__),"r") as f: | |||
# print (f.read()) | |||
# aa = {'loglevel': 'error'} | |||
# process = ( | |||
# ffmpeg | |||
# .input("http://cmgw-vpc.lechange.com:8888/LCO/8D0B355PAN8B3B3/0/0/20221019T130437/eabfe43d95971e0ae03de28dad4fd4ce.m3u8", **aa) | |||
# .output('pipe:', format='rawvideo', pix_fmt='bgr24', loglevel='error')# , bufsize='1000000k' | |||
# .overwrite_output() | |||
# .global_args('-an') | |||
# .run_async(pipe_stdout=True) | |||
# ) | |||
# self.pull_p = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE) | |||
cap = cv2.VideoCapture("http://cmgw-vpc.lechange.com:8888/LCO/8D0B355PAN8B3B3/0/0/20221019T130437/eabfe43d95971e0ae03de28dad4fd4ce.m3u8") | |||
fps = int(cap.get(cv2.CAP_PROP_FPS)) | |||
print(fps) | |||
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |||
print(width) | |||
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |||
print(height) | |||
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC)) | |||
print(fourcc) | |||
# print(cv2.getBuildInformation()) | |||
# cap.setExceptionMode(True) | |||
# print(cap.getExceptionMode()) | |||
# cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) | |||
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) | |||
# cap.set(cv2.CAP_PROP_FPS, 25) | |||
command = ['ffmpeg', | |||
'-y', # 不经过确认,输出时直接覆盖同名文件。 | |||
'-f', 'rawvideo', | |||
'-vcodec','rawvideo', | |||
'-pix_fmt', 'bgr24', | |||
# '-r', str(13), | |||
'-s', "{}x{}".format(width, height), | |||
# '-s', "{}x{}".format(1280, 720), | |||
'-i', '-', # 指定输入文件 | |||
'-c:v', 'libx264', # 指定视频编码器 | |||
'-pix_fmt', 'yuv420p', | |||
"-an", | |||
# '-b:v', '3000k', | |||
'-preset', 'ultrafast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# superfast, veryfast, faster, fast, medium, slow, slower, veryslow。 | |||
'-f', 'flv', | |||
"rtmp://live.push.t-aaron.com/live/THSAq"] | |||
# # 管道配置 | |||
p = sp.Popen(command, stdin=sp.PIPE) | |||
# while(cap.isOpened()): | |||
while True: | |||
start =time.time() | |||
# in_bytes = process.stdout.read(1920 * 1080 * 3) | |||
# result = (np.frombuffer(in_bytes, np.uint8).reshape([1080, 1920, 3])) | |||
# time.sleep(0.04) | |||
ret, frame = cap.read() | |||
# print(cap.grab()) | |||
# print("aaaaaaaaaaaaaa", time.time()-start) | |||
# start =time.time() | |||
# a,b = cap.retrieve() | |||
# print("bbbbbbbbbbbbbb", time.time()-start) | |||
# if not ret: | |||
# print("Opening camera is failed") | |||
# break | |||
# cv2.namedWindow('picture',0) | |||
# cv2.resizeWindow("picture", 1980, 1080) | |||
# cv2.imshow('picture', result) | |||
# cv2.waitKey(1) & 0xFF == ord('q') | |||
p.stdin.write(frame.tostring()) | |||
@@ -1,7 +1,7 @@ | |||
from PIL import Image | |||
from pixelmatch.contrib.PIL import pixelmatch | |||
img_a = Image.open("image/AI.jpg") | |||
img_b = Image.open("image/AI3.jpg") | |||
img_a = Image.open("../image/AI.jpg") | |||
img_b = Image.open("../image/AI3.jpg") | |||
img_diff = Image.new("RGBA", img_a.size) | |||
# note how there is no need to specify dimensions | |||
mismatch = pixelmatch(img_a, img_b, img_diff, includeAA=True) |
@@ -101,7 +101,7 @@ class Water: | |||
if __name__ == '__main__': | |||
img = Image.open("a.jpg") | |||
img = Image.open("../a.jpg") | |||
fontcolor = 'yellow' | |||
water = Water() |
@@ -10,8 +10,6 @@ from loguru import logger | |||
from exception.CustomerException import ServiceException | |||
from enums.ExceptionEnum import ExceptionType | |||
class Cv2Util(): | |||
def __init__(self, pullUrl, pushUrl=None, orFilePath=None, aiFilePath=None, requestId=None): | |||
@@ -26,6 +24,7 @@ class Cv2Util(): | |||
self.fps = None | |||
self.width = None | |||
self.height = None | |||
self.wh = None | |||
self.all_frames = None | |||
self.bit_rate = None | |||
self.pull_p = None | |||
@@ -35,6 +34,7 @@ class Cv2Util(): | |||
''' | |||
获取视频信息 | |||
''' | |||
def get_video_info(self): | |||
try: | |||
if self.pullUrl is None: | |||
@@ -59,6 +59,8 @@ class Cv2Util(): | |||
self.width = int(width) | |||
if height: | |||
self.height = int(height) | |||
if width is not None and height is not None: | |||
self.wh = int(width * height * 3 / 4) | |||
if nb_frames: | |||
self.all_frames = int(nb_frames) | |||
if fps: | |||
@@ -67,7 +69,7 @@ class Cv2Util(): | |||
# if duration: | |||
# self.duration = float(video_stream['duration']) | |||
if bit_rate: | |||
self.bit_rate = int(bit_rate)/1000 | |||
self.bit_rate = int(bit_rate) / 1000 | |||
logger.info("视频信息, width:{}|height:{}|fps:{}|all_frames:{}|bit_rate:{}, requestId:{}", self.width, | |||
self.height, self.fps, self.all_frames, self.bit_rate, self.requestId) | |||
except ServiceException as s: | |||
@@ -76,11 +78,16 @@ class Cv2Util(): | |||
except Exception as e: | |||
logger.exception("获取视频信息异常:{}, requestId:{}", e, self.requestId) | |||
''' | |||
拉取视频 | |||
''' | |||
def build_pull_p(self): | |||
try: | |||
if self.width is None or self.height is None: | |||
return | |||
if self.pull_p: | |||
logger.info("重试, 关闭拉流管道, requestId:{}", self.requestId) | |||
self.pull_p.stdout.close() | |||
@@ -99,10 +106,12 @@ class Cv2Util(): | |||
# # '-s', "{}x{}".format(int(width), int(height)), | |||
# '-an', | |||
# '-'] | |||
aa = {'loglevel': 'error'} | |||
process = ( | |||
ffmpeg | |||
.input(self.pullUrl) | |||
.output('pipe:', format='rawvideo', pix_fmt='bgr24') | |||
.input(self.pullUrl, **aa) | |||
.output('pipe:', format='rawvideo', pix_fmt='bgr24', loglevel='error', | |||
s="{}x{}".format(int(self.width / 2), int(self.height / 2))) | |||
.overwrite_output() | |||
.global_args('-an') | |||
.run_async(pipe_stdout=True) | |||
@@ -123,13 +132,13 @@ class Cv2Util(): | |||
def read(self): | |||
result = None | |||
try: | |||
if self.pull_p is None: | |||
logger.error("拉流管道为空, requestId:{}", self.requestId) | |||
raise ServiceException(ExceptionType.PULL_PIPELINE_INIT_EXCEPTION.value[0], | |||
ExceptionType.PULL_PIPELINE_INIT_EXCEPTION.value[1]) | |||
in_bytes = self.pull_p.stdout.read(self.width * self.height * 3) | |||
# if self.pull_p is None: | |||
# logger.error("拉流管道为空, requestId:{}", self.requestId) | |||
# raise ServiceException(ExceptionType.PULL_PIPELINE_INIT_EXCEPTION.value[0], | |||
# ExceptionType.PULL_PIPELINE_INIT_EXCEPTION.value[1]) | |||
in_bytes = self.pull_p.stdout.read(self.wh) | |||
if in_bytes is not None and len(in_bytes) > 0: | |||
result = (np.frombuffer(in_bytes, np.uint8).reshape([self.height, self.width, 3])) | |||
result = (np.frombuffer(in_bytes, np.uint8).reshape([int(self.height / 2), int(self.width / 2), 3])) | |||
except ServiceException as s: | |||
logger.exception("读流异常: {}, requestId:{}", s, self.requestId) | |||
except Exception as e: | |||
@@ -159,67 +168,67 @@ class Cv2Util(): | |||
logger.info("关闭AI视频写入流完成, requestId:{}", self.requestId) | |||
# 构建 cv2 | |||
def build_cv2(self): | |||
try: | |||
if self.cap is not None: | |||
logger.info("重试, 关闭cap, requestId:{}", self.requestId) | |||
self.cap.release() | |||
if self.p is not None: | |||
logger.info("重试, 关闭管道, requestId:{}", self.requestId) | |||
self.p.stdin.close() | |||
self.p.terminate() | |||
self.p.wait() | |||
if self.pullUrl is None: | |||
logger.error("拉流地址不能为空, requestId:{}", self.requestId) | |||
raise ServiceException(ExceptionType.PULL_STREAM_URL_EXCEPTION.value[0], | |||
ExceptionType.PULL_STREAM_URL_EXCEPTION.value[1]) | |||
if self.pushUrl is None: | |||
logger.error("推流地址不能为空, requestId:{}", self.requestId) | |||
raise ServiceException(ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[0], | |||
ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[1]) | |||
self.cap = cv2.VideoCapture(self.pullUrl) | |||
if self.fps is None or self.fps == 0: | |||
self.fps = int(self.cap.get(cv2.CAP_PROP_FPS)) | |||
if self.width is None or self.width == 0: | |||
self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |||
if self.height is None or self.height == 0: | |||
self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |||
command = ['/usr/bin/ffmpeg', | |||
# '-y', # 不经过确认,输出时直接覆盖同名文件。 | |||
'-f', 'rawvideo', | |||
'-vcodec', 'rawvideo', | |||
'-pix_fmt', 'bgr24', # 显示可用的像素格式 | |||
# '-s', "{}x{}".format(self.width * 2, self.height), | |||
'-s', "{}x{}".format(int(self.width), int(self.height/2)), | |||
# '-r', str(15), | |||
'-i', '-', # 指定输入文件 | |||
'-g', '25', | |||
'-b:v', '3000k', | |||
'-tune', 'zerolatency', # 加速编码速度 | |||
'-c:v', 'libx264', # 指定视频编码器 | |||
'-sc_threshold', '0', | |||
'-pix_fmt', 'yuv420p', | |||
'-an', | |||
'-preset', 'ultrafast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# superfast, veryfast, faster, fast, medium, slow, slower, veryslow。 | |||
'-f', 'flv', | |||
self.pushUrl] | |||
# 管道配置 | |||
logger.info("fps:{}|height:{}|width:{}|requestId:{}", self.fps, self.height, self.width, self.requestId) | |||
self.p = sp.Popen(command, stdin=sp.PIPE) | |||
except ServiceException as s: | |||
logger.exception("构建cv2异常: {}, requestId:{}", s, self.requestId) | |||
raise s | |||
except Exception as e: | |||
logger.exception("初始化cv2异常:{}, requestId:{}", e, self.requestId) | |||
# def build_cv2(self): | |||
# try: | |||
# if self.cap is not None: | |||
# logger.info("重试, 关闭cap, requestId:{}", self.requestId) | |||
# self.cap.release() | |||
# if self.p is not None: | |||
# logger.info("重试, 关闭管道, requestId:{}", self.requestId) | |||
# self.p.stdin.close() | |||
# self.p.terminate() | |||
# self.p.wait() | |||
# if self.pullUrl is None: | |||
# logger.error("拉流地址不能为空, requestId:{}", self.requestId) | |||
# raise ServiceException(ExceptionType.PULL_STREAM_URL_EXCEPTION.value[0], | |||
# ExceptionType.PULL_STREAM_URL_EXCEPTION.value[1]) | |||
# if self.pushUrl is None: | |||
# logger.error("推流地址不能为空, requestId:{}", self.requestId) | |||
# raise ServiceException(ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[0], | |||
# ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[1]) | |||
# self.cap = cv2.VideoCapture(self.pullUrl) | |||
# if self.fps is None or self.fps == 0: | |||
# self.fps = int(self.cap.get(cv2.CAP_PROP_FPS)) | |||
# if self.width is None or self.width == 0: | |||
# self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |||
# if self.height is None or self.height == 0: | |||
# self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |||
# command = ['/usr/bin/ffmpeg', | |||
# # '-y', # 不经过确认,输出时直接覆盖同名文件。 | |||
# '-f', 'rawvideo', | |||
# '-vcodec', 'rawvideo', | |||
# '-pix_fmt', 'bgr24', # 显示可用的像素格式 | |||
# # '-s', "{}x{}".format(self.width * 2, self.height), | |||
# '-s', "{}x{}".format(int(self.width), int(self.height/2)), | |||
# # '-r', str(15), | |||
# '-i', '-', # 指定输入文件 | |||
# '-g', '25', | |||
# '-b:v', '3000k', | |||
# '-tune', 'zerolatency', # 加速编码速度 | |||
# '-c:v', 'libx264', # 指定视频编码器 | |||
# '-sc_threshold', '0', | |||
# '-pix_fmt', 'yuv420p', | |||
# '-an', | |||
# '-preset', 'ultrafast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# # superfast, veryfast, faster, fast, medium, slow, slower, veryslow。 | |||
# '-f', 'flv', | |||
# self.pushUrl] | |||
# # 管道配置 | |||
# logger.info("fps:{}|height:{}|width:{}|requestId:{}", self.fps, self.height, self.width, self.requestId) | |||
# self.p = sp.Popen(command, stdin=sp.PIPE) | |||
# except ServiceException as s: | |||
# logger.exception("构建cv2异常: {}, requestId:{}", s, self.requestId) | |||
# raise s | |||
# except Exception as e: | |||
# logger.exception("初始化cv2异常:{}, requestId:{}", e, self.requestId) | |||
# 构建 cv2 | |||
# 构建 cv2 | |||
def build_p(self): | |||
try: | |||
if self.p: | |||
logger.info("重试, 关闭管道, requestId:{}", self.requestId) | |||
self.p.stdin.close() | |||
if self.p.stdin: | |||
self.p.stdin.close() | |||
self.p.terminate() | |||
self.p.wait() | |||
# self.p.communicate() | |||
@@ -229,26 +238,28 @@ class Cv2Util(): | |||
raise ServiceException(ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[0], | |||
ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[1]) | |||
command = ['ffmpeg', | |||
# '-loglevel', 'debug', | |||
'-y', # 不经过确认,输出时直接覆盖同名文件。 | |||
'-f', 'rawvideo', | |||
'-vcodec', 'rawvideo', | |||
'-pix_fmt', 'bgr24', | |||
# '-s', "{}x{}".format(self.width * 2, self.height), | |||
'-s', "{}x{}".format(int(self.width), int(self.height/2)), | |||
'-s', "{}x{}".format(int(self.width), int(self.height / 2)), | |||
'-r', str(self.fps), | |||
'-i', '-', # 指定输入文件 | |||
'-g', str(self.fps), | |||
# '-maxrate', '15000k', | |||
'-b:v', '6000k', | |||
# '-crf', '18',s | |||
'-bufsize', '6000k', | |||
'-tune', 'zerolatency', # 加速编码速度 | |||
# '-profile:v', 'high', | |||
'-b:v', '4000k', | |||
# '-crf', '18', | |||
'-bufsize', '4000k', | |||
'-c:v', 'libx264', # 指定视频编码器 | |||
'-tune', 'zerolatency', # 加速编码速度 | |||
'-sc_threshold', '0', | |||
'-pix_fmt', 'yuv420p', | |||
"-an", | |||
# '-flvflags', 'no_duration_filesize', | |||
'-preset', 'medium', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
'-preset', 'veryfast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# superfast, veryfast, faster, fast, medium, slow, slower, veryslow。 | |||
'-f', 'flv', | |||
self.pushUrl] | |||
@@ -259,21 +270,22 @@ class Cv2Util(): | |||
# ' -f flv ' + self.pushUrl | |||
# kwargs = {'format': 'rawvideo', | |||
# 'vcodec': 'rawvideo', | |||
# # 'vcodec': 'rawvideo', | |||
# 'pix_fmt': 'bgr24', | |||
# 's': '{}x{}'.format(int(self.width), int(self.height/2))} | |||
# out = { | |||
# 'r': str(self.fps), | |||
# 'g': str(self.fps), | |||
# 'b:v': '8000k', # 恒定码率 | |||
# 'maxrate': '15000k', | |||
# 'b:v': '5500k', # 恒定码率 | |||
# # 'maxrate': '15000k', | |||
# # 'crf': '18', | |||
# 'bufsize': '3000k', | |||
# 'bufsize': '5500k', | |||
# 'tune': 'zerolatency', # 加速编码速度 | |||
# 'c:v': 'libx264', # 指定视频编码器 | |||
# 'sc_threshold': '0', | |||
# 'pix_fmt': 'yuv420p', | |||
# # 'flvflags': 'no_duration_filesize', | |||
# 'preset': 'ultrafast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# 'preset': 'medium', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, | |||
# # superfast, veryfast, faster, fast, medium, slow, slower, veryslow。 | |||
# 'format': 'flv'} | |||
# 管道配置 | |||
@@ -281,13 +293,12 @@ class Cv2Util(): | |||
# ffmpeg | |||
# .input('pipe:', **kwargs) | |||
# .output(self.pushUrl, **out) | |||
# .global_args('-re', '-y', '-an') | |||
# .global_args('-y', '-an') | |||
# .overwrite_output() | |||
# .run_async(pipe_stdin=True) | |||
# ) | |||
logger.info("fps:{}|height:{}|width:{}|requestId:{}", self.fps, self.height, self.width, self.requestId) | |||
self.p = sp.Popen(command, stdin=sp.PIPE, shell=False) | |||
# self.p = process2 | |||
except ServiceException as s: | |||
logger.exception("构建p管道异常: {}, requestId:{}", s, self.requestId) | |||
@@ -305,12 +316,13 @@ class Cv2Util(): | |||
current_retry_num = 0 | |||
while True: | |||
try: | |||
if self.p_push_retry_num > 500: | |||
if self.p_push_retry_num > 20: | |||
logger.info("推流失败重试次数过多, 请检查相关配置信息, 当前重试次数: {}, requestId: {}", | |||
self.p_push_retry_num, self.requestId) | |||
current_retry_num = 4 | |||
break | |||
self.p_push_retry_num += 1 | |||
time.sleep(10) | |||
self.build_p() | |||
self.p.stdin.write(frame.tostring()) | |||
logger.info("构建p管道重试成功, 当前重试次数: {}, requestId: {}", current_retry_num, | |||
@@ -354,7 +366,6 @@ class Cv2Util(): | |||
raise ServiceException(ExceptionType.SERVICE_INNER_EXCEPTION.value[0], | |||
ExceptionType.SERVICE_INNER_EXCEPTION.value[1]) | |||
def build_write(self): | |||
try: | |||
if self.fps is None or self.width is None or self.height is None: | |||
@@ -362,13 +373,13 @@ class Cv2Util(): | |||
ExceptionType.VIDEO_CONFIG_EXCEPTION.value[1]) | |||
if self.orFilePath is not None and self.or_video_file is None: | |||
self.or_video_file = cv2.VideoWriter(self.orFilePath, cv2.VideoWriter_fourcc(*'mp4v'), self.fps, | |||
(self.width, self.height)) | |||
(int(self.width / 2), int(self.height / 2))) | |||
if self.or_video_file is None: | |||
raise ServiceException(ExceptionType.OR_WRITE_OBJECT_EXCEPTION.value[0], | |||
ExceptionType.OR_WRITE_OBJECT_EXCEPTION.value[1]) | |||
if self.aiFilePath is not None and self.ai_video_file is None: | |||
self.ai_video_file = cv2.VideoWriter(self.aiFilePath, cv2.VideoWriter_fourcc(*'mp4v'), self.fps, | |||
(int(self.width), int(self.height/2))) | |||
(int(self.width), int(self.height / 2))) | |||
if self.ai_video_file is None: | |||
raise ServiceException(ExceptionType.AI_WRITE_OBJECT_EXCEPTION.value[0], | |||
ExceptionType.AI_WRITE_OBJECT_EXCEPTION.value[1]) | |||
@@ -380,8 +391,8 @@ class Cv2Util(): | |||
raise e | |||
def video_merge(self, frame1, frame2): | |||
frameLeft = cv2.resize(frame1, (int(self.width/2), int(self.height/2)), interpolation=cv2.INTER_LINEAR) | |||
frameRight = cv2.resize(frame2, (int(self.width/2), int(self.height/2)), interpolation=cv2.INTER_LINEAR) | |||
frameLeft = cv2.resize(frame1, (int(self.width / 2), int(self.height / 2)), interpolation=cv2.INTER_LINEAR) | |||
frameRight = cv2.resize(frame2, (int(self.width / 2), int(self.height / 2)), interpolation=cv2.INTER_LINEAR) | |||
frame_merge = np.hstack((frameLeft, frameRight)) | |||
# frame_merge = np.hstack((frame1, frame2)) | |||
return frame_merge |
@@ -41,11 +41,18 @@ class SZModel(Model): | |||
if self.label_arraylist is None: | |||
fontsize = int(width/1920*40) | |||
line_thickness = 1 | |||
if width > 1280: | |||
line_thickness = int(round(width/1920*3)) | |||
waterLineWidth = int(round(width/1920*3) + 1) | |||
numFontSize = float(format(width/1920*1.1, '.1f')) | |||
self.digitFont = {'line_thickness': line_thickness, 'fontSize': numFontSize, 'waterLineColor':(0,255,255), 'waterLineWidth': waterLineWidth} | |||
boxLine_thickness = 1 | |||
waterLineWidth = 1 | |||
if width >= 960: | |||
line_thickness = int(round(width/1920*3) - 1) | |||
boxLine_thickness = int(round(width/1920*3)) | |||
waterLineWidth = int(round(width/1920*3)) | |||
numFontSize = float(format(width/1920*1.1, '.1f')) # 文字大小 | |||
self.digitFont = {'line_thickness': line_thickness, | |||
'boxLine_thickness': boxLine_thickness, | |||
'fontSize': numFontSize, | |||
'waterLineColor': (0, 255, 255), | |||
'waterLineWidth': waterLineWidth} | |||
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=fontsize, | |||
fontpath="../AIlib/conf/platech.ttf") | |||
return AI_process([frame], self.model, self.segmodel, self.names, self.label_arraylist, | |||
@@ -73,11 +80,18 @@ class LCModel(Model): | |||
if self.label_arraylist is None: | |||
fontsize = int(width/1920*40) | |||
line_thickness = 1 | |||
if width > 1280: | |||
line_thickness = int(round(width/1920*3)) | |||
waterLineWidth = int(round(width/1920*3) + 1) | |||
numFontSize = float(format(width/1920*1.1, '.1f')) | |||
self.digitFont = {'line_thickness': line_thickness, 'fontSize': numFontSize, 'waterLineColor':(0,255,255), 'waterLineWidth': waterLineWidth} ###数字显示的线宽度,大小; 如果都是None,则采用默认大小 | |||
boxLine_thickness = 1 | |||
waterLineWidth = 1 | |||
if width >= 960: | |||
line_thickness = int(round(width/1920*3) - 1) | |||
boxLine_thickness = int(round(width/1920*3)) | |||
waterLineWidth = int(round(width/1920*3)) | |||
numFontSize = float(format(width/1920*1.1, '.1f')) # 文字大小 | |||
self.digitFont = {'line_thickness': line_thickness, | |||
'boxLine_thickness': boxLine_thickness, | |||
'fontSize': numFontSize, | |||
'waterLineColor': (0, 255, 255), | |||
'waterLineWidth': waterLineWidth} | |||
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=fontsize, fontpath="../AIlib/conf/platech.ttf") | |||
return AI_process_forest([frame], self.model, self.segmodel, self.names, self.label_arraylist, | |||
self.rainbows, self.half, self.device, self.conf_thres, self.iou_thres, | |||
@@ -103,11 +117,19 @@ class RFModel(Model): | |||
if self.label_arraylist is None: | |||
fontsize = int(width/1920*40) | |||
line_thickness = 1 | |||
if width > 1280: | |||
line_thickness = int(round(width/1920*3)) | |||
waterLineWidth = int(round(width/1920*3) + 1) | |||
boxLine_thickness = 1 | |||
waterLineWidth = 1 | |||
if width >= 960: | |||
line_thickness = int(round(width/1920*3) - 1) | |||
boxLine_thickness = int(round(width/1920*2)) | |||
waterLineWidth = int(round(width/1920*3)) | |||
numFontSize = float(format(width/1920*1.1, '.1f')) | |||
self.digitFont = {'line_thickness': line_thickness, 'fontSize': numFontSize, 'waterLineColor':(0,255,255), 'waterLineWidth': waterLineWidth} ###数字显示的线宽度,大小; 如果都是None,则采用默认大小 | |||
self.digitFont = {'line_thickness': line_thickness, | |||
'boxLine_thickness': boxLine_thickness, | |||
'fontSize': numFontSize, | |||
'waterLineColor': (0, 255, 255), | |||
'waterLineWidth': waterLineWidth} | |||
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=fontsize, fontpath="../AIlib/conf/platech.ttf") | |||
return AI_process_forest([frame], self.model, self.segmodel, self.names, self.label_arraylist, | |||
self.rainbows, self.half, self.device, self.conf_thres, self.iou_thres, |