微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JPEG 参数结构不匹配:库认为大小为 584,调用者期望 Jetson 中的 python3 为 728

如何解决JPEG 参数结构不匹配:库认为大小为 584,调用者期望 Jetson 中的 python3 为 728

我正在尝试从 here

为 YOLO 运行darknet_video.py 脚本

在 Jetson(nano 和 xavier NX)中。代码一个 nano 中运行良好,但在另一个 nano 和 NX 中运行良好。该脚本在 Ubuntu 18.04 (Jetpack) 中使用以下命令运行

python3 darknet_video.py --input test.mp4 --out_filename out1.txt --weights yolov3-tiny.weights --ext_output --config_file yolov3-tiny.cfg --data_file coco.data --thresh 0.2

我收到以下错误

JPEG parameter struct mismatch: library thinks size is 584,caller expects 728
pure virtual method called
terminate called without an active exception
Aborted (core dumped)

由于它在一nano中运行良好,可能是依赖性问题,这是darknet_video.py中的代码

from ctypes import *
import random
import os
import cv2
import time
import darknet
import argparse
from threading import Thread,enumerate
from queue import Queue


def parser():
    parser = argparse.ArgumentParser(description="YOLO Object Detection")
    parser.add_argument("--input",type=str,default=0,help="video source. If empty,uses webcam 0 stream")
    parser.add_argument("--out_filename",default="",help="inference video name. Not saved if empty")
    parser.add_argument("--weights",default="yolov4.weights",help="yolo weights path")
    parser.add_argument("--dont_show",action='store_true',help="windown inference display. For headless systems")
    parser.add_argument("--ext_output",help="display bBox coordinates of detected objects")
    parser.add_argument("--config_file",default="./cfg/yolov4.cfg",help="path to config file")
    parser.add_argument("--data_file",default="./cfg/coco.data",help="path to data file")
    parser.add_argument("--thresh",type=float,default=.25,help="remove detections with confidence below this value")
    return parser.parse_args()


def str2int(video_path):
    """
    argparse returns and string althout webcam uses int (0,1 ...)
    Cast to int if needed
    """
    try:
        return int(video_path)
    except ValueError:
        return video_path


def check_arguments_errors(args):
    assert 0 < args.thresh < 1,"Threshold should be a float between zero and one (non-inclusive)"
    if not os.path.exists(args.config_file):
        raise(ValueError("Invalid config path {}".format(os.path.abspath(args.config_file))))
    if not os.path.exists(args.weights):
        raise(ValueError("Invalid weight path {}".format(os.path.abspath(args.weights))))
    if not os.path.exists(args.data_file):
        raise(ValueError("Invalid data file path {}".format(os.path.abspath(args.data_file))))
    if str2int(args.input) == str and not os.path.exists(args.input):
        raise(ValueError("Invalid video path {}".format(os.path.abspath(args.input))))


def set_saved_video(input_video,output_video,size):
    fourcc = cv2.VideoWriter_fourcc(*"MJPG")
    fps = int(input_video.get(cv2.CAP_PROP_FPS))
    video = cv2.VideoWriter(output_video,fourcc,fps,size)
    return video


def video_capture(frame_queue,darknet_image_queue):
    while cap.isOpened():
        ret,frame = cap.read()
        if not ret:
            break
        frame_rgb = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        frame_resized = cv2.resize(frame_rgb,(width,height),interpolation=cv2.INTER_LINEAR)
        frame_queue.put(frame_resized)
        img_for_detect = darknet.make_image(width,height,3)
        darknet.copy_image_from_bytes(img_for_detect,frame_resized.tobytes())
        darknet_image_queue.put(img_for_detect)
    cap.release()


def inference(darknet_image_queue,detections_queue,fps_queue):
    while cap.isOpened():
        darknet_image = darknet_image_queue.get()
        prev_time = time.time()
        detections = darknet.detect_image(network,class_names,darknet_image,thresh=args.thresh)
        detections_queue.put(detections)
        fps = int(1/(time.time() - prev_time))
        fps_queue.put(fps)
        print("FPS: {}".format(fps))
        darknet.print_detections(detections,args.ext_output)
        darknet.free_image(darknet_image)
    cap.release()


def drawing(frame_queue,fps_queue):
    random.seed(3)  # deterministic bBox colors
    video = set_saved_video(cap,args.out_filename,height))
    while cap.isOpened():
        frame_resized = frame_queue.get()
        detections = detections_queue.get()
        fps = fps_queue.get()
        if frame_resized is not None:
            image = darknet.draw_Boxes(detections,frame_resized,class_colors)
            image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
            if args.out_filename is not None:
                video.write(image)
            if not args.dont_show:
                cv2.imshow('Inference',image)
            if cv2.waitKey(fps) == 27:
                break
    cap.release()
    video.release()
    cv2.destroyAllWindows()


if __name__ == '__main__':
    frame_queue = Queue()
    darknet_image_queue = Queue(maxsize=1)
    detections_queue = Queue(maxsize=1)
    fps_queue = Queue(maxsize=1)

    args = parser()
    check_arguments_errors(args)
    network,class_colors = darknet.load_network(
            args.config_file,args.data_file,args.weights,batch_size=1
        )
    width = darknet.network_width(network)
    height = darknet.network_height(network)
    input_path = str2int(args.input)
    cap = cv2.VideoCapture(input_path)
    Thread(target=video_capture,args=(frame_queue,darknet_image_queue)).start()
    Thread(target=inference,args=(darknet_image_queue,fps_queue)).start()
    Thread(target=drawing,fps_queue)).start()

任何想法将不胜感激。

解决方法

JPEG 参数结构不匹配:库认为大小为 584,调用者期望为 728

这是关于应用和低级库使用的 jpeglib.h
应用程序是用不同的 jpeglib.h 编译的,低级库是用不同的 jpeglib.h 和结构编译的,在这种情况下,它在这个头文件中的 j_decompress_ptr 在这两个不同的 jpeglib.h 中是不同的文件。

确保您有低级别的 lib(可能是 libjpeg-8b)及其客户端使用相同的 libjpeg.h

删除所有已安装的 libjpeg 软件包并仅安装最新的一个并尝试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。