{"id":1184355,"date":"2025-01-15T19:25:31","date_gmt":"2025-01-15T11:25:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1184355.html"},"modified":"2025-01-15T19:25:33","modified_gmt":"2025-01-15T11:25:33","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%bf%9b%e8%a1%8c%e8%a7%86%e9%a2%91%e6%a0%87%e6%b3%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1184355.html","title":{"rendered":"\u5982\u4f55\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25133822\/ffa7e5cb-ceb1-4bab-a87c-c586dc12081f.webp\" alt=\"\u5982\u4f55\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\" \/><\/p>\n<p><p> <strong>\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u7684\u6700\u4f73\u65b9\u6cd5\u662f\u4f7f\u7528OpenCV\u3001MoviePy\u3001\u4ee5\u53caLabelImg\u7b49\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u89c6\u9891\u7684\u52a0\u8f7d\u3001\u5904\u7406\u3001\u6807\u6ce8\u548c\u8f93\u51fa\u3002<\/strong> \u5728\u8fd9\u4e9b\u5de5\u5177\u4e2d\uff0cOpenCV\u4e3b\u8981\u7528\u4e8e\u89c6\u9891\u7684\u52a0\u8f7d\u548c\u5904\u7406\uff0cMoviePy\u7528\u4e8e\u89c6\u9891\u7f16\u8f91\u548c\u5904\u7406\uff0c\u800cLabelImg\u5219\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u56fe\u50cf\u6807\u6ce8\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u6807\u6ce8\u6587\u4ef6\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528OpenCV\u8fdb\u884c\u89c6\u9891\u52a0\u8f7d\u548c\u5904\u7406<\/h3>\n<\/p>\n<p><h4>1.1 \u5b89\u88c5OpenCV<\/h4>\n<\/p>\n<p><p>\u8981\u4f7f\u7528OpenCV\u8fdb\u884c\u89c6\u9891\u5904\u7406\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5OpenCV\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u52a0\u8f7d\u89c6\u9891<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528OpenCV\u52a0\u8f7d\u89c6\u9891\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cv2.VideoCapture<\/code>\u51fd\u6570\u6765\u52a0\u8f7d\u89c6\u9891\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u52a0\u8f7d\u89c6\u9891\u6587\u4ef6<\/strong><\/h2>\n<p>video_path = &#39;path_to_your_video.mp4&#39;<\/p>\n<p>cap = cv2.VideoCapture(video_path)<\/p>\n<h2><strong>\u68c0\u67e5\u89c6\u9891\u662f\u5426\u6210\u529f\u52a0\u8f7d<\/strong><\/h2>\n<p>if not cap.isOpened():<\/p>\n<p>    print(&quot;Error: Could not open video.&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Video successfully loaded.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.3 \u8bfb\u53d6\u89c6\u9891\u5e27<\/h4>\n<\/p>\n<p><p>\u52a0\u8f7d\u89c6\u9891\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cap.read()<\/code>\u51fd\u6570\u9010\u5e27\u8bfb\u53d6\u89c6\u9891\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while cap.isOpened():<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    # \u5728\u6b64\u5904\u5bf9\u6bcf\u4e00\u5e27\u8fdb\u884c\u5904\u7406<\/p>\n<p>    cv2.imshow(&#39;Frame&#39;, frame)<\/p>\n<p>    # \u6309\u952e\u9000\u51fa<\/p>\n<p>    if cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<h2><strong>\u91ca\u653e\u89c6\u9891\u5bf9\u8c61<\/strong><\/h2>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528MoviePy\u8fdb\u884c\u89c6\u9891\u7f16\u8f91\u548c\u5904\u7406<\/h3>\n<\/p>\n<p><h4>2.1 \u5b89\u88c5MoviePy<\/h4>\n<\/p>\n<p><p>MoviePy\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u89c6\u9891\u7f16\u8f91\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5bf9\u89c6\u9891\u8fdb\u884c\u5404\u79cd\u7f16\u8f91\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install moviepy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u52a0\u8f7d\u548c\u5904\u7406\u89c6\u9891<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528MoviePy\u52a0\u8f7d\u548c\u5904\u7406\u89c6\u9891\u4e5f\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from moviepy.editor import VideoFileClip<\/p>\n<h2><strong>\u52a0\u8f7d\u89c6\u9891\u6587\u4ef6<\/strong><\/h2>\n<p>video_path = &#39;path_to_your_video.mp4&#39;<\/p>\n<p>clip = VideoFileClip(video_path)<\/p>\n<h2><strong>\u663e\u793a\u89c6\u9891\u4fe1\u606f<\/strong><\/h2>\n<p>print(f&quot;Duration: {clip.duration} seconds&quot;)<\/p>\n<p>print(f&quot;FPS: {clip.fps}&quot;)<\/p>\n<p>print(f&quot;Resolution: {clip.size}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.3 \u5bf9\u89c6\u9891\u8fdb\u884c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>MoviePy\u63d0\u4f9b\u4e86\u8bb8\u591a\u65b9\u4fbf\u7684\u89c6\u9891\u64cd\u4f5c\u51fd\u6570\uff0c\u4f8b\u5982\u88c1\u526a\u3001\u6dfb\u52a0\u6587\u672c\u3001\u5408\u5e76\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from moviepy.editor import TextClip, CompositeVideoClip<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u672c\u5230\u89c6\u9891<\/strong><\/h2>\n<p>text = TextClip(&quot;Hello, MoviePy!&quot;, fontsize=70, color=&#39;white&#39;)<\/p>\n<p>text = text.set_pos(&#39;center&#39;).set_duration(5)<\/p>\n<h2><strong>\u5408\u5e76\u6587\u672c\u548c\u89c6\u9891<\/strong><\/h2>\n<p>result = CompositeVideoClip([clip, text])<\/p>\n<h2><strong>\u4fdd\u5b58\u5904\u7406\u540e\u7684\u89c6\u9891<\/strong><\/h2>\n<p>result.write_videofile(&quot;output_video.mp4&quot;, codec=&#39;libx264&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528LabelImg\u8fdb\u884c\u56fe\u50cf\u6807\u6ce8<\/h3>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5LabelImg<\/h4>\n<\/p>\n<p><p>LabelImg\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u56fe\u50cf\u6807\u6ce8\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u6807\u6ce8\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install labelImg<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u8fdb\u884c\u6807\u6ce8<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u542f\u52a8LabelImg\u8fdb\u884c\u56fe\u50cf\u6807\u6ce8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">labelImg<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728LabelImg\u4e2d\uff0c\u53ef\u4ee5\u6253\u5f00\u89c6\u9891\u7684\u6bcf\u4e00\u5e27\u56fe\u50cf\u8fdb\u884c\u6807\u6ce8\uff0c\u5e76\u5c06\u6807\u6ce8\u7ed3\u679c\u4fdd\u5b58\u4e3aXML\u6216YOLO\u683c\u5f0f\u6587\u4ef6\u3002\u5177\u4f53\u64cd\u4f5c\u53ef\u4ee5\u53c2\u8003LabelImg\u7684\u4f7f\u7528\u6587\u6863\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5c06\u6807\u6ce8\u7ed3\u679c\u5e94\u7528\u5230\u89c6\u9891\u4e2d<\/h3>\n<\/p>\n<p><h4>4.1 \u8bfb\u53d6\u6807\u6ce8\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6839\u636e\u6807\u6ce8\u6587\u4ef6\u683c\u5f0f\uff0c\u53ef\u4ee5\u7f16\u5199\u4ee3\u7801\u8bfb\u53d6\u6807\u6ce8\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528YOLO\u683c\u5f0f\uff0c\u53ef\u4ee5\u8fd9\u6837\u8bfb\u53d6\u6807\u6ce8\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_yolo_label(file_path):<\/p>\n<p>    labels = []<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        lines = file.readlines()<\/p>\n<p>        for line in lines:<\/p>\n<p>            labels.append([float(x) for x in line.strip().split()])<\/p>\n<p>    return labels<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>labels = read_yolo_label(&#39;path_to_yolo_label.txt&#39;)<\/p>\n<p>print(labels)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u5728\u89c6\u9891\u5e27\u4e2d\u7ed8\u5236\u6807\u6ce8<\/h4>\n<\/p>\n<p><p>\u8bfb\u53d6\u6807\u6ce8\u7ed3\u679c\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528OpenCV\u5728\u89c6\u9891\u5e27\u4e2d\u7ed8\u5236\u6807\u6ce8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u793a\u4f8b\u6807\u6ce8\u7ed3\u679c<\/strong><\/h2>\n<p>labels = [<\/p>\n<p>    [0, 0.5, 0.5, 0.2, 0.2]  # [class_id, center_x, center_y, width, height]<\/p>\n<p>]<\/p>\n<p>def draw_labels(frame, labels):<\/p>\n<p>    height, width, _ = frame.shape<\/p>\n<p>    for label in labels:<\/p>\n<p>        class_id, cx, cy, w, h = label<\/p>\n<p>        left = int((cx - w \/ 2) * width)<\/p>\n<p>        top = int((cy - h \/ 2) * height)<\/p>\n<p>        right = int((cx + w \/ 2) * width)<\/p>\n<p>        bottom = int((cy + h \/ 2) * height)<\/p>\n<p>        # \u7ed8\u5236\u77e9\u5f62\u6846<\/p>\n<p>        cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)<\/p>\n<h2><strong>\u52a0\u8f7d\u89c6\u9891\u5e76\u7ed8\u5236\u6807\u6ce8<\/strong><\/h2>\n<p>cap = cv2.VideoCapture(&#39;path_to_your_video.mp4&#39;)<\/p>\n<p>while cap.isOpened():<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    draw_labels(frame, labels)<\/p>\n<p>    cv2.imshow(&#39;Frame&#39;, frame)<\/p>\n<p>    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u7ed3\u5408\u6240\u6709\u6b65\u9aa4\u5b9e\u73b0\u5b8c\u6574\u89c6\u9891\u6807\u6ce8\u6d41\u7a0b<\/h3>\n<\/p>\n<p><h4>5.1 \u8bfb\u53d6\u89c6\u9891\u5e27\u5e76\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u8bfb\u53d6\u89c6\u9891\u5e27\u5e76\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\uff0c\u4ee5\u4fbf\u4f7f\u7528LabelImg\u8fdb\u884c\u6807\u6ce8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import cv2<\/p>\n<p>video_path = &#39;path_to_your_video.mp4&#39;<\/p>\n<p>output_dir = &#39;frames\/&#39;<\/p>\n<p>if not os.path.exists(output_dir):<\/p>\n<p>    os.makedirs(output_dir)<\/p>\n<p>cap = cv2.VideoCapture(video_path)<\/p>\n<p>frame_count = 0<\/p>\n<p>while cap.isOpened():<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    frame_path = os.path.join(output_dir, f&#39;frame_{frame_count:04d}.jpg&#39;)<\/p>\n<p>    cv2.imwrite(frame_path, frame)<\/p>\n<p>    frame_count += 1<\/p>\n<p>cap.release()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u4f7f\u7528LabelImg\u5bf9\u56fe\u50cf\u8fdb\u884c\u6807\u6ce8<\/h4>\n<\/p>\n<p><p>\u542f\u52a8LabelImg\uff0c\u5bf9\u4fdd\u5b58\u7684\u56fe\u50cf\u8fdb\u884c\u6807\u6ce8\uff0c\u5e76\u5c06\u6807\u6ce8\u7ed3\u679c\u4fdd\u5b58\u4e3aYOLO\u683c\u5f0f\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>5.3 \u8bfb\u53d6\u6807\u6ce8\u7ed3\u679c\u5e76\u5e94\u7528\u5230\u89c6\u9891\u4e2d<\/h4>\n<\/p>\n<p><p>\u8bfb\u53d6\u6807\u6ce8\u7ed3\u679c\uff0c\u5e76\u5728\u539f\u89c6\u9891\u4e2d\u7ed8\u5236\u6807\u6ce8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>def read_yolo_labels(label_dir, frame_count):<\/p>\n<p>    labels = []<\/p>\n<p>    for i in range(frame_count):<\/p>\n<p>        label_path = os.path.join(label_dir, f&#39;frame_{i:04d}.txt&#39;)<\/p>\n<p>        if os.path.exists(label_path):<\/p>\n<p>            labels.append(read_yolo_label(label_path))<\/p>\n<p>        else:<\/p>\n<p>            labels.append([])<\/p>\n<p>    return labels<\/p>\n<p>def draw_labels(frame, labels):<\/p>\n<p>    height, width, _ = frame.shape<\/p>\n<p>    for label in labels:<\/p>\n<p>        class_id, cx, cy, w, h = label<\/p>\n<p>        left = int((cx - w \/ 2) * width)<\/p>\n<p>        top = int((cy - h \/ 2) * height)<\/p>\n<p>        right = int((cx + w \/ 2) * width)<\/p>\n<p>        bottom = int((cy + h \/ 2) * height)<\/p>\n<p>        cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)<\/p>\n<p>video_path = &#39;path_to_your_video.mp4&#39;<\/p>\n<p>label_dir = &#39;labels\/&#39;<\/p>\n<p>output_video = &#39;output_video.mp4&#39;<\/p>\n<p>cap = cv2.VideoCapture(video_path)<\/p>\n<p>frame_width = int(cap.get(3))<\/p>\n<p>frame_height = int(cap.get(4))<\/p>\n<p>fps = int(cap.get(5))<\/p>\n<p>out = cv2.VideoWriter(output_video, cv2.VideoWriter_fourcc(*&#39;mp4v&#39;), fps, (frame_width, frame_height))<\/p>\n<p>frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))<\/p>\n<p>labels = read_yolo_labels(label_dir, frame_count)<\/p>\n<p>frame_index = 0<\/p>\n<p>while cap.isOpened():<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    draw_labels(frame, labels[frame_index])<\/p>\n<p>    out.write(frame)<\/p>\n<p>    frame_index += 1<\/p>\n<p>cap.release()<\/p>\n<p>out.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4ece\u89c6\u9891\u5e27\u63d0\u53d6\u3001\u56fe\u50cf\u6807\u6ce8\u5230\u6807\u6ce8\u7ed3\u679c\u5e94\u7528\u7684\u5b8c\u6574\u6d41\u7a0b\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528Python\u5bf9\u89c6\u9891\u8fdb\u884c\u6807\u6ce8\uff0c\u5e76\u751f\u6210\u5e26\u6709\u6807\u6ce8\u7684\u8f93\u51fa\u89c6\u9891\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u7684\u5b8c\u6574\u6d41\u7a0b\u3002\u9996\u5148\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528OpenCV\u52a0\u8f7d\u548c\u5904\u7406\u89c6\u9891\uff0c\u7136\u540e\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528MoviePy\u8fdb\u884c\u89c6\u9891\u7f16\u8f91\u548c\u5904\u7406\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528LabelImg\u8fdb\u884c\u56fe\u50cf\u6807\u6ce8\uff0c\u6700\u540e\u5c06\u6807\u6ce8\u7ed3\u679c\u5e94\u7528\u5230\u89c6\u9891\u4e2d\uff0c\u5e76\u751f\u6210\u5e26\u6709\u6807\u6ce8\u7684\u8f93\u51fa\u89c6\u9891\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u89c6\u9891\u8fdb\u884c\u6807\u6ce8\u548c\u5904\u7406\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u89c6\u9891\u5206\u6790\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u5e94\u7528\u573a\u666f\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u8ba9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528OpenCV\u3001MoviePy\u6216LabelImg\u7b49\u5e93\u6765\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u3002OpenCV\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u8bfb\u53d6\u89c6\u9891\u5e27\u5e76\u5728\u5e27\u4e0a\u6dfb\u52a0\u6807\u6ce8\u3002MoviePy\u5219\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684API\uff0c\u4f7f\u5f97\u89c6\u9891\u5904\u7406\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002LabelImg\u4e3b\u8981\u7528\u4e8e\u56fe\u50cf\u6807\u6ce8\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7ed3\u5408Python\u811a\u672c\u6765\u5904\u7406\u89c6\u9891\u5e27\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9bPython\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\uff1f<\/strong><br \/>\u5e38\u7528\u7684Python\u5e93\u5305\u62ecOpenCV\u3001MoviePy\u548cFFmpeg\u3002OpenCV\u9002\u5408\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u6bcf\u4e00\u5e27\u7684\u6807\u6ce8\uff0c\u800cMoviePy\u9002\u5408\u5feb\u901f\u5904\u7406\u548c\u6dfb\u52a0\u7b80\u5355\u6807\u6ce8\u7684\u573a\u666f\u3002FFmpeg\u5219\u53ef\u4ee5\u7528\u4e8e\u89c6\u9891\u7684\u8f6c\u6362\u548c\u5904\u7406\uff0c\u914d\u5408Python\u811a\u672c\u4f7f\u7528\u80fd\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6807\u6ce8\u9700\u6c42\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u4fdd\u5b58\u5e26\u6709\u6807\u6ce8\u7684\u89c6\u9891\uff1f<\/strong><br \/>\u5728Python\u4e2d\u4fdd\u5b58\u5e26\u6709\u6807\u6ce8\u7684\u89c6\u9891\uff0c\u53ef\u4ee5\u4f7f\u7528OpenCV\u7684<code>VideoWriter<\/code>\u7c7b\u3002\u60a8\u9700\u8981\u6307\u5b9a\u8f93\u51fa\u89c6\u9891\u7684\u6587\u4ef6\u540d\u3001\u7f16\u7801\u683c\u5f0f\u3001\u5e27\u7387\u548c\u89c6\u9891\u5c3a\u5bf8\u3002\u901a\u8fc7\u9010\u5e27\u5904\u7406\u89c6\u9891\uff0c\u53ef\u4ee5\u5728\u6bcf\u4e00\u5e27\u4e0a\u6dfb\u52a0\u6807\u6ce8\uff0c\u7136\u540e\u5c06\u5e26\u6709\u6807\u6ce8\u7684\u5e27\u5199\u5165\u8f93\u51fa\u89c6\u9891\u6587\u4ef6\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u6807\u6ce8\u5185\u5bb9\u80fd\u591f\u5728\u6700\u7ec8\u89c6\u9891\u4e2d\u6e05\u6670\u53ef\u89c1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u8fdb\u884c\u89c6\u9891\u6807\u6ce8\u7684\u6700\u4f73\u65b9\u6cd5\u662f\u4f7f\u7528OpenCV\u3001MoviePy\u3001\u4ee5\u53caLabelImg\u7b49\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef [&hellip;]","protected":false},"author":3,"featured_media":1184362,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184355"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1184355"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184355\/revisions"}],"predecessor-version":[{"id":1184364,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184355\/revisions\/1184364"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1184362"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1184355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1184355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1184355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}