Browse Source

算法交互添加4090TRT模型,集成钓鱼游泳模型、违法种植模型

tags/V2.6.1
chenyukun 1 year ago
parent
commit
a7e022b262
27 changed files with 802 additions and 569 deletions
  1. +7
    -0
      .idea/deployment.xml
  2. +1
    -0
      .idea/sshConfigs.xml
  3. +8
    -1
      .idea/webServers.xml
  4. +35
    -8
      .idea/workspace.xml
  5. +16
    -9
      concurrency/IntelligentRecognitionProcess.py
  6. +12
    -8
      enums/ModelTypeEnum.py
  7. BIN
      enums/__pycache__/ModelTypeEnum.cpython-38.pyc
  8. BIN
      enums/__pycache__/__init__.cpython-38.pyc
  9. BIN
      service/__pycache__/Dispatcher.cpython-310.pyc
  10. BIN
      service/__pycache__/__init__.cpython-310.pyc
  11. BIN
      test/image/1.jpg
  12. BIN
      test/image/11.jpg
  13. BIN
      test/image/2.jpg
  14. BIN
      test/image/22.jpg
  15. BIN
      test/image/AI.jpg
  16. BIN
      test/image/AI1.jpg
  17. BIN
      test/image/AI2.jpg
  18. BIN
      test/image/AI3.jpg
  19. BIN
      test/image/AI4.jpg
  20. BIN
      test/image/AI5.jpg
  21. BIN
      test/image/AI6.jpg
  22. BIN
      test/image/AI7.jpg
  23. BIN
      test/image/AI8.jpg
  24. +21
    -5
      test/str/test.py
  25. +3
    -3
      test/水印/余弦相似度计算.py
  26. +57
    -38
      util/Cv2Utils.py
  27. +642
    -497
      util/ModelUtils.py

+ 7
- 0
.idea/deployment.xml View File

@@ -9,6 +9,13 @@
</mappings>
</serverdata>
</paths>
<paths name="10.22">
<serverdata>
<mappings>
<mapping deploy="/home/th/tuo_heng/prod/tuoheng_alg" local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="66">
<serverdata>
<mappings>

+ 1
- 0
.idea/sshConfigs.xml View File

@@ -4,6 +4,7 @@
<configs>
<sshConfig authType="PASSWORD" host="192.168.10.66" id="aa89844a-f7c0-47b6-9359-30d13fa76380" port="22" nameFormat="DESCRIPTIVE" username="thsw2" />
<sshConfig authType="PASSWORD" host="192.168.10.21" id="adf5e1da-4910-4668-bfbb-432f4e2ae77c" port="22" nameFormat="DESCRIPTIVE" username="th" />
<sshConfig authType="PASSWORD" host="192.168.10.22" id="ac18a75e-ff42-4875-a5da-ad98d2d695ea" port="22" nameFormat="DESCRIPTIVE" username="th" />
</configs>
</component>
</project>

+ 8
- 1
.idea/webServers.xml View File

@@ -17,7 +17,14 @@
</fileTransfer>
</webServer>
<webServer id="c24476df-a574-465f-9529-a8e029b84f34" name="10.21">
<fileTransfer accessType="SFTP" host="192.168.10.21" port="22" sshConfigId="adf5e1da-4910-4668-bfbb-432f4e2ae77c" sshConfig="th@192.168.10.21:22 password">
<fileTransfer accessType="SFTP" host="192.168.10.22" port="22" sshConfigId="ac18a75e-ff42-4875-a5da-ad98d2d695ea" sshConfig="th@192.168.10.22:22 password">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions>
</fileTransfer>
</webServer>
<webServer id="575fb0f8-1aa4-4ab8-8952-1657964a0673" name="10.22">
<fileTransfer accessType="SFTP" host="192.168.10.22" port="22" sshConfigId="ac18a75e-ff42-4875-a5da-ad98d2d695ea" sshConfig="th@192.168.10.22:22 password">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions>

+ 35
- 8
.idea/workspace.xml View File

@@ -5,7 +5,27 @@
</component>
<component name="ChangeListManager">
<list default="true" id="4f7dccd9-8f92-4a6e-90cc-33890d102263" name="Changes" comment="Changes">
<change beforePath="$PROJECT_DIR$/.idea/deployment.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/deployment.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sshConfigs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sshConfigs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/webServers.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/webServers.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$/enums/ModelTypeEnum.py" beforeDir="false" afterPath="$PROJECT_DIR$/enums/ModelTypeEnum.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/1.jpg" beforeDir="false" afterPath="$PROJECT_DIR$/test/image/1.jpg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/2.jpg" beforeDir="false" afterPath="$PROJECT_DIR$/test/image/2.jpg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI1.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI2.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI3.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI4.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI5.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI6.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI7.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/image/AI8.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test/str/test.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/str/test.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/水印/余弦相似度计算.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/水印/余弦相似度计算.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" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -131,7 +151,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/dsp/tuoheng_dsp" />
<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)" />
@@ -156,7 +176,7 @@
<recent name="D:\work\alg\tuoheng_alg\image" />
</key>
</component>
<component name="RunManager" selected="Python.producer_start1">
<component name="RunManager" selected="Python.test">
<configuration name="aa" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
@@ -274,13 +294,13 @@
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="$PROJECT_DIR$/../../../software/anaconda/envs/test/python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/while" />
<option name="SDK_HOME" value="D:\software\anaconda\envs\chenyukun\python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/str" />
<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="$PROJECT_DIR$/test/while/test.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/str/test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -292,18 +312,18 @@
<list>
<item itemvalue="Python.mysqltest" />
<item itemvalue="Python.producer_start" />
<item itemvalue="Python.test" />
<item itemvalue="Python.aa" />
<item itemvalue="Python.ffmpeg33" />
<item itemvalue="Python.producer_start1" />
<item itemvalue="Python.test" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.test" />
<item itemvalue="Python.producer_start1" />
<item itemvalue="Python.aa" />
<item itemvalue="Python.ffmpeg33" />
<item itemvalue="Python.producer_start" />
<item itemvalue="Python.test" />
</list>
</recent_temporary>
</component>
@@ -384,6 +404,13 @@
<workItem from="1672797232144" duration="25138000" />
<workItem from="1672877597405" duration="5633000" />
<workItem from="1672967214543" duration="2590000" />
<workItem from="1673483697794" duration="13972000" />
<workItem from="1674003653469" duration="751000" />
<workItem from="1674089698944" duration="1180000" />
<workItem from="1674174312546" duration="591000" />
<workItem from="1674953245041" duration="2374000" />
<workItem from="1675038738781" duration="20967000" />
<workItem from="1675126111623" duration="613000" />
</task>
<servers />
</component>
@@ -424,7 +451,7 @@
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<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$test.coverage" NAME="test 覆盖结果" MODIFIED="1669793778903" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/while" />
<SUITE FILE_PATH="coverage/tuoheng_alg$test.coverage" NAME="test 覆盖结果" MODIFIED="1675048794635" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/str" />
<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="1670489109246" 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" />

+ 16
- 9
concurrency/IntelligentRecognitionProcess.py View File

@@ -119,7 +119,10 @@ class IntelligentRecognitionProcess(Process):

def process(frame):
try:
p_result, timeOut = frame[1].process(copy.deepcopy(frame[0].get("frame")), int(frame[0].get("width") / 2))
width = int(frame[0].get("width"))
if width > 1600:
width = width // 2
p_result, timeOut = frame[1].process(copy.deepcopy(frame[0].get("frame")), width)
if frame[2]["video"]["video_add_water"]:
frame[0]["frame"] = frame[3].common_water_1(frame[0].get("frame"), frame[3].logo)
p_result[1] = frame[3].common_water_1(p_result[1], frame[3].logo)
@@ -1053,21 +1056,25 @@ def get_model(args):
logger.info("######################开始加载模型######################")
model_config = {
# 加载河道模型
ModelType.WATER_SURFACE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.SZModel(x, y, z, r), ModelType.WATER_SURFACE_MODEL.value[1]),
ModelType.WATER_SURFACE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.WATER_SURFACE_MODEL), ModelType.WATER_SURFACE_MODEL.value[1]),
# 加载林场模型
ModelType.FOREST_FARM_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.LCModel(x, y, z, r), ModelType.FOREST_FARM_MODEL.value[1]),
ModelType.FOREST_FARM_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.FOREST_FARM_MODEL), ModelType.FOREST_FARM_MODEL.value[1]),
# 加载交通模型
ModelType.TRAFFIC_FARM_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.RFModel(x, y, z, r), ModelType.TRAFFIC_FARM_MODEL.value[1]),
ModelType.TRAFFIC_FARM_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.TRAFFIC_FARM_MODEL), ModelType.TRAFFIC_FARM_MODEL.value[1]),
# 加载防疫模型
ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.IMModel(x, y, z, r), ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]),
ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.IMModel(x, y, z, r, ModelType.EPIDEMIC_PREVENTION_MODEL), ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]),
# 加载车牌模型
ModelType.PLATE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.PlateMModel(x, y, z, r), ModelType.PLATE_MODEL.value[1]),
ModelType.PLATE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.IMModel(x, y, z, r, ModelType.PLATE_MODEL), ModelType.PLATE_MODEL.value[1]),
# 加载车辆模型
ModelType.Vehicle_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.VehicleModel(x, y, z, r), ModelType.Vehicle_MODEL.value[1]),
ModelType.VEHICLE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.VEHICLE_MODEL), ModelType.VEHICLE_MODEL.value[1]),
# 加载行人模型
ModelType.Pedestrian_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.PedestrianModel(x, y, z, r), ModelType.Pedestrian_MODEL.value[1]),
ModelType.PEDESTRIAN_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.PEDESTRIAN_MODEL), ModelType.PEDESTRIAN_MODEL.value[1]),
# 加载烟火模型
ModelType.Smogfire_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.SmogfireModel(x, y, z, r), ModelType.Smogfire_MODEL.value[1])
ModelType.SMOGFIRE_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.SMOGFIRE_MODEL), ModelType.SMOGFIRE_MODEL.value[1]),
# 加载钓鱼游泳模型
ModelType.ANGLERSWIMMER_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.ANGLERSWIMMER_MODEL), ModelType.ANGLERSWIMMER_MODEL.value[1]),
# 加载乡村模型
ModelType.COUNTRYROAD_MODEL.value[1]: (lambda x, y, z, r: ModelUtils.Model(x, y, z, r, ModelType.COUNTRYROAD_MODEL), ModelType.COUNTRYROAD_MODEL.value[1])
}
for model in args[1]:
try:

+ 12
- 8
enums/ModelTypeEnum.py View File

@@ -5,21 +5,25 @@ from enum import Enum, unique
@unique
class ModelType(Enum):

WATER_SURFACE_MODEL = ("1", "001", "河道模型")
WATER_SURFACE_MODEL = ("1", "001", "河道模型", 'river')

FOREST_FARM_MODEL = ("2", "002", "森林模型")
FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest')

TRAFFIC_FARM_MODEL = ("3", "003", "交通模型")
TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'road')

EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型")
EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型", None)

PLATE_MODEL = ("5", "005", "车牌模型")
PLATE_MODEL = ("5", "005", "车牌模型", None)

Vehicle_MODEL = ("6", "006", "车辆模型")
VEHICLE_MODEL = ("6", "006", "车辆模型", 'vehicle')

Pedestrian_MODEL = ("7", "007", "行人模型")
PEDESTRIAN_MODEL = ("7", "007", "行人模型", 'pedestrian')

Smogfire_MODEL = ("8", "008", "烟火模型")
SMOGFIRE_MODEL = ("8", "008", "烟火模型", 'smogfire')

ANGLERSWIMMER_MODEL = ("9", "009", "钓鱼游泳模型", 'AnglerSwimmer')

COUNTRYROAD_MODEL = ("10", "010", "乡村模型", 'countryRoad')

def checkCode(code):
for model in ModelType:

BIN
enums/__pycache__/ModelTypeEnum.cpython-38.pyc View File


BIN
enums/__pycache__/__init__.cpython-38.pyc View File


BIN
service/__pycache__/Dispatcher.cpython-310.pyc View File


BIN
service/__pycache__/__init__.cpython-310.pyc View File


BIN
test/image/1.jpg View File

Before After
Width: 640  |  Height: 360  |  Size: 113KB Width: 960  |  Height: 540  |  Size: 200KB

BIN
test/image/11.jpg View File

Before After
Width: 960  |  Height: 540  |  Size: 228KB

BIN
test/image/2.jpg View File

Before After
Width: 640  |  Height: 360  |  Size: 119KB Width: 960  |  Height: 540  |  Size: 196KB

BIN
test/image/22.jpg View File

Before After
Width: 960  |  Height: 540  |  Size: 213KB

BIN
test/image/AI.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 477KB

BIN
test/image/AI1.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 462KB

BIN
test/image/AI2.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 436KB

BIN
test/image/AI3.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 417KB

BIN
test/image/AI4.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 422KB

BIN
test/image/AI5.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 423KB

BIN
test/image/AI6.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 414KB

BIN
test/image/AI7.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 411KB

BIN
test/image/AI8.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 430KB

+ 21
- 5
test/str/test.py View File

@@ -5,9 +5,25 @@
# else:
# a = '%s,%s' % (a, str(i))
# print(a)
a=[1,2,3,4,5,8, 9]
b=[1,3,2]
if set(a) >= set(b):
print("a")
# a=[1,2,3,4,5,8, 9]
# b=[1,3,2]
# if set(a) >= set(b):
# print("a")
# else:
# print("b")
from enums.ModelTypeEnum import ModelType

if ModelType.WATER_SURFACE_MODEL == ModelType.FOREST_FARM_MODEL:
print("aaaaa")
else:
print("b")
print("bbbbbbbbbb")

if isinstance(ModelType.WATER_SURFACE_MODEL, ModelType):
print("aaaaa")
else:
print("bbbbbbbbbb")

if type(ModelType.WATER_SURFACE_MODEL)==ModelType.FOREST_FARM_MODEL:
print("aaaaa")
else:
print("bbbbbbbbbb")

+ 3
- 3
test/水印/余弦相似度计算.py View File

@@ -63,8 +63,8 @@ def Hamming_distance(hash1,hash2):

if __name__ == '__main__':
# 把图片表示成一个向量,通过计算向量之间的余弦距离来表征两张图片的相似度 0.9760
image1 = cv2.imread('image/1.jpg')
image2 = cv2.imread('image/1.jpg')
image1 = cv2.imread('../image/1.jpg')
image2 = cv2.imread('../image/2.jpg')
# image3 = cv2.imread('image/AI2.jpg')
# image4 = cv2.imread('image/AI3.jpg')
# image5 = cv2.imread('image/AI4.jpg')
@@ -81,7 +81,7 @@ if __name__ == '__main__':
dist = Hamming_distance(hash1, hash2)
#将距离转化为相似度
similarity = 1 - dist * 1.0 / 64
print(dist)
# print(dist)
print(similarity, time.time() - start)
# cosin = image_similarity_vectors_via_numpy(image1, image2)
# print('图片余弦相似度', cosin)

+ 57
- 38
util/Cv2Utils.py View File

@@ -43,21 +43,29 @@ class Cv2Util():
self.fps = fps
self.width = width
self.height = height
self.wh = int(width * height * 3 // 8)
self.wah = '%sx%s' % (int(self.width / 2), int(self.height / 2))
self.h = int(self.height * 3 // 4)
self.w = int(self.width // 2)
self.hn = int(self.height // 2)
self.wn = int(self.width // 2)
w_f = self.wh != width * height * 3 / 8
h_f = self.h != self.height * 3 / 4
wd_f = self.w != self.width / 2
if w_f or h_f or wd_f:
self.resize_status = True
if width > 1600:
self.wh = int(width * height * 3 // 8)
self.wah = '%sx%s' % (int(self.width / 2), int(self.height / 2))
self.h = int(self.height * 3 // 4)
self.w = int(self.width // 2)
self.hn = int(self.height // 2)
self.wn = int(self.width // 2)
w_f = self.wh != width * height * 3 / 8
h_f = self.h != self.height * 3 / 4
wd_f = self.w != self.width / 2
if w_f or h_f or wd_f:
self.resize_status = True
self.wh = int(width * height * 3 // 2)
self.wah = '%sx%s' % (int(self.width), int(self.height))
self.h = int(self.height * 3 // 2)
self.w = int(self.width)
else:
self.wh = int(width * height * 3 // 2)
self.wah = '%sx%s' % (int(self.width), int(self.height))
self.h = int(self.height * 3 // 2)
self.w = int(self.width)
self.hn = int(self.height)
self.wn = int(self.width)

'''
获取视频信息
@@ -85,26 +93,32 @@ class Cv2Util():
fps = video_stream.get('r_frame_rate')
# duration = video_stream.get('duration')
bit_rate = video_stream.get('bit_rate')
if width:
self.width = int(width)
if height:
self.height = int(height)
self.width = int(width)
self.height = int(height)
if width is not None and height is not None:
self.wh = int(width * height * 3 // 8)
self.wah = '%sx%s' % (int(self.width / 2), int(self.height / 2))
self.h = int(self.height * 3 // 4)
self.w = int(self.width / 2)
self.hn = int(self.height / 2)
self.wn = int(self.width // 2)
w_f = self.wh != width * height * 3 / 8
h_f = self.h != self.height * 3 / 4
wd_f = self.w != self.width / 2
if w_f or h_f or wd_f:
self.resize_status = True
if width > 1600:
self.wh = int(width * height * 3 // 8)
self.wah = '%sx%s' % (int(self.width / 2), int(self.height / 2))
self.h = int(self.height * 3 // 4)
self.w = int(self.width / 2)
self.hn = int(self.height / 2)
self.wn = int(self.width // 2)
w_f = self.wh != width * height * 3 / 8
h_f = self.h != self.height * 3 / 4
wd_f = self.w != self.width / 2
if w_f or h_f or wd_f:
self.resize_status = True
self.wh = int(width * height * 3 // 2)
self.wah = '%sx%s' % (int(self.width), int(self.height))
self.h = int(self.height * 3 // 2)
self.w = int(self.width)
else:
self.wh = int(width * height * 3 // 2)
self.wah = '%sx%s' % (int(self.width), int(self.height))
self.h = int(self.height * 3 // 2)
self.w = int(self.width)
self.hn = int(self.height)
self.wn = int(self.width)
if nb_frames:
self.all_frames = int(nb_frames)
if fps:
@@ -197,8 +211,9 @@ class Cv2Util():
ExceptionType.VIDEO_RESOLUTION_EXCEPTION.value[1])
result = cv2.cvtColor(img, cv2.COLOR_YUV2BGR_NV12)
if self.resize_status:
result = cv2.resize(result, (int(self.width / 2), int(self.height / 2)),
interpolation=cv2.INTER_LINEAR)
if self.width > 1600:
result = cv2.resize(result, (int(self.width / 2), int(self.height / 2)),
interpolation=cv2.INTER_LINEAR)
except ServiceException as s:
raise s
except Exception as e:
@@ -297,6 +312,9 @@ class Cv2Util():
logger.error("推流地址不能为空, requestId:{}", self.requestId)
raise ServiceException(ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[0],
ExceptionType.PUSH_STREAM_URL_EXCEPTION.value[1])
width = int(self.width)
if width <= 1600:
width = 2 * int(self.width)
command = ['ffmpeg',
# '-loglevel', 'debug',
'-y',
@@ -305,28 +323,29 @@ class Cv2Util():
'-pix_fmt', 'bgr24',
'-thread_queue_size', '1024',
# '-s', "{}x{}".format(self.width * 2, self.height),
'-s', "{}x{}".format(int(self.width), int(self.hn)),
'-s', "{}x{}".format(width, int(self.hn)),
'-r', str(self.fps),
'-i', '-', # 指定输入文件
'-g', str(self.fps),
# '-maxrate', '15000k',
'-maxrate', '8000k',
# '-profile:v', 'high',
# '-b:v', '4000k',
'-b:v', '5000k',
# '-crf', '18',
'-rc:v', 'vbr',
'-cq:v', '30',
'-qmin', '30',
'-qmax', '30',
# '-rc:v', 'vbr',
# '-cq:v', '25',
# '-qmin', '25',
# '-qmax', '25',
'-c:v', 'h264_nvenc', #
# '-bufsize', '4000k',
'-bufsize', '5000k',
# '-c:v', 'libx264', # 指定视频编码器
# '-tune', 'zerolatency', # 加速编码速度
# '-sc_threshold', '0',
'-pix_fmt', 'yuv420p',
"-an",
# '-flvflags', 'no_duration_filesize',
'-preset', 'fast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast,
# superfast, veryfast, faster, fast, medium, slow, slower, veryslow。
# '-preset', 'fast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast,
'-preset', 'p6', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast,
'-tune', 'll',
'-f', 'flv',
self.pushUrl]
# command = 'ffmpeg -loglevel debug -y -f rawvideo -vcodec rawvideo -pix_fmt bgr24' +\

+ 642
- 497
util/ModelUtils.py
File diff suppressed because it is too large
View File


Loading…
Cancel
Save