Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将颜色校正opencv模块示例从C++;巨蟒_Python_C++_Opencv_Colors - Fatal编程技术网

Python 将颜色校正opencv模块示例从C++;巨蟒

Python 将颜色校正opencv模块示例从C++;巨蟒,python,c++,opencv,colors,Python,C++,Opencv,Colors,我尝试在示例中转换颜色校正模块 但我遇到了一些困难,因为我不知道C++,< /P> //compte color correction matrix ColorCorrectionModel model1(src, COLORCHECKER_Vinyl); model1.run(); Mat ccm = model1.getCCM(); std::cout<<"ccm "<<ccm<<std::end

我尝试在示例中转换颜色校正模块 但我遇到了一些困难,因为我不知道C++,< /P>
    //compte color correction matrix
    ColorCorrectionModel model1(src, COLORCHECKER_Vinyl);
    model1.run();
    Mat ccm = model1.getCCM();
    std::cout<<"ccm "<<ccm<<std::endl;
    double loss = model1.getLoss();
    std::cout<<"loss "<<loss<<std::endl;
但请告诉我这个错误

colorCorrectionModel.run()

cv2.error:OpenCV(4.5.1)C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-sljz46fi\OpenCV\modules\core\src\arithm.cpp:234:error:(-209:输入参数的大小不匹配)操作既不是“array op array”(其中数组具有相同的大小和类型),也不是“array op scalar”,也不是函数“cv::binary\u op”中的“scalar op array”

如何更正此错误

示例:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2
import numpy as np

image = cv2.imread('input.jpg')
detector = cv2.mcc.CCheckerDetector_create()
detector.process(image, cv2.mcc.MCC24, 1)

checkers = detector.getListColorChecker()
for checker in checkers:
    cdraw = cv2.mcc.CCheckerDraw_create(checker)
    img_draw = image.copy()
    cdraw.draw(img_draw)
    
    chartsRGB = checker.getChartsRGB()
    width, height = chartsRGB.shape[:2]
    roi = chartsRGB[0:width,1]
    print (roi)
    rows = int(roi.shape[:1][0])
    src = chartsRGB[:,1].copy().reshape(int(rows/3), 1, 3)
    src /= 255
    #print(src.shape)

    model = cv2.ccm_ColorCorrectionModel(src, cv2.ccm.COLORCHECKER_Macbeth)
    model.setColorSpace(cv2.ccm.COLOR_SPACE_sRGB)
    model.setCCM_TYPE(cv2.ccm.CCM_3x3)
    model.setDistance(cv2.ccm.DISTANCE_CIE2000)
    model.setLinear(cv2.ccm.LINEARIZATION_GAMMA)
    model.setLinearGamma(2.2)
    model.setLinearDegree(3)
    model.setSaturatedThreshold(0, 0.98)
    model.run()

    ccm = model.getCCM()
    print ('ccm:\n{}\n'.format(ccm))
    loss = model.getLoss()
    print ('loss:\n{}\n'.format(loss))

    img_ = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    img_ = img_.astype(np.float64)
    img_ = img_/255
    calibratedImage = model.infer(img_)
    out_ = calibratedImage * 255
    out_[out_ < 0] = 0
    out_[out_ > 255] = 255
    out_ = out_.astype(np.uint8)
     
    out_img = cv2.cvtColor(out_, cv2.COLOR_RGB2BGR)
    cv2.imwrite('output.jpg', out_img);

    width, height = image.shape[:2]
    image = cv2.resize(image, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    img_draw = cv2.resize(img_draw, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    out_img = cv2.resize(out_img, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    cv2.namedWindow('Image')
    cv2.imshow("Image",image)
    cv2.imshow('img_draw', img_draw)
    cv2.imshow('Out Image', out_img)
    cv2.waitKey(0)

cv2.destroyAllWindows()
#/usr/bin/python
#-*-编码:utf-8-*-
进口cv2
将numpy作为np导入
image=cv2.imread('input.jpg')
检测器=cv2.mcc.CCheckerDetector_create()
探测器。过程(图像,cv2.mcc.MCC24,1)
checkers=detector.getListColorChecker()
对于棋盘格中的棋盘格:
cdraw=cv2.mcc.CCheckerDraw\u创建(检查程序)
img_draw=image.copy()
图纸绘制(图纸绘制)
chartsRGB=checker.getChartsRGB()
宽度、高度=图表GB.形状[:2]
roi=chartsRGB[0:宽度,1]
打印(roi)
rows=int(roi.shape[:1][0])
src=chartsRGB[:,1].copy().reformate(int(rows/3),1,3)
src/=255
#打印(src.shape)
model=cv2.ccm\u ColorCorrectionModel(src,cv2.ccm.COLORCHECKER\u Macbeth)
model.setColorSpace(cv2.ccm.COLOR\u SPACE\u sRGB)
model.setCCM_TYPE(cv2.ccm.ccm_3x3)
型号设定距离(cv2.ccm.DISTANCE_CIE2000)
模型设置线性化(cv2.ccm.LINEARIZATION_GAMMA)
型号:setLinearGamma(2.2)
模型。setLinearDegree(3)
型号设置饱和阈值(0,0.98)
model.run()
ccm=model.getCCM()
打印('ccm:\n{}\n'.格式(ccm))
loss=model.getLoss()
打印('丢失:\n{}\n'。格式(丢失))
img=cv2.CVT颜色(图像,cv2.COLOR\u BGR2RGB)
img=img.astype(np.float64)
img_uu=img_uu/255
校准图像=模型。推断(img_u2;)
输出=校准图像*255
out\u0[out\u0<0]=0
out_uu[out_uu>255]=255
out=out类型(np.uint8)
out\u img=cv2.cvt颜色(out\u,cv2.COLOR\u RGB2BGR)
cv2.imwrite('output.jpg',out\u img);
宽度,高度=图像。形状[:2]
image=cv2.resize(image,(int(高度/4)、int(宽度/4)),插值=cv2.INTER_CUBIC)
img_draw=cv2.调整大小(img_draw,(int(高度/4),int(宽度/4)),插值=cv2.内部立方)
out\u img=cv2.调整大小(out\u img,(int(高度/4),int(宽度/4)),插值=cv2.内部立方)
cv2.namedWindow(“图像”)
cv2.imshow(“图像”,图像)
cv2.imshow(“img_图纸”,img_图纸)
cv2.imshow(“输出图像”,输出图像)
cv2.等待键(0)
cv2.destroyAllWindows()

更多的人有这个问题:没有解决方案被报告。C++代码(DOCs上的教程代码。OpenCV.org)有一个三通道数据(VEC3D)的列矩阵,因为API期望这种数据。由于OpenCV的cv::Mat/np.array转换逻辑,此形状映射为
(-1,1,3)
(自动行、1列、3通道)的numpy形状。请提供进一步的上下文,如:此代码如何工作?另一个用户将如何调整此代码以满足其需求?哪些行对于更改校正算法至关重要?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2
import numpy as np

image = cv2.imread('input.jpg')
detector = cv2.mcc.CCheckerDetector_create()
detector.process(image, cv2.mcc.MCC24, 1)

checkers = detector.getListColorChecker()
for checker in checkers:
    cdraw = cv2.mcc.CCheckerDraw_create(checker)
    img_draw = image.copy()
    cdraw.draw(img_draw)
    
    chartsRGB = checker.getChartsRGB()
    width, height = chartsRGB.shape[:2]
    roi = chartsRGB[0:width,1]
    print (roi)
    rows = int(roi.shape[:1][0])
    src = chartsRGB[:,1].copy().reshape(int(rows/3), 1, 3)
    src /= 255
    #print(src.shape)

    model = cv2.ccm_ColorCorrectionModel(src, cv2.ccm.COLORCHECKER_Macbeth)
    model.setColorSpace(cv2.ccm.COLOR_SPACE_sRGB)
    model.setCCM_TYPE(cv2.ccm.CCM_3x3)
    model.setDistance(cv2.ccm.DISTANCE_CIE2000)
    model.setLinear(cv2.ccm.LINEARIZATION_GAMMA)
    model.setLinearGamma(2.2)
    model.setLinearDegree(3)
    model.setSaturatedThreshold(0, 0.98)
    model.run()

    ccm = model.getCCM()
    print ('ccm:\n{}\n'.format(ccm))
    loss = model.getLoss()
    print ('loss:\n{}\n'.format(loss))

    img_ = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    img_ = img_.astype(np.float64)
    img_ = img_/255
    calibratedImage = model.infer(img_)
    out_ = calibratedImage * 255
    out_[out_ < 0] = 0
    out_[out_ > 255] = 255
    out_ = out_.astype(np.uint8)
     
    out_img = cv2.cvtColor(out_, cv2.COLOR_RGB2BGR)
    cv2.imwrite('output.jpg', out_img);

    width, height = image.shape[:2]
    image = cv2.resize(image, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    img_draw = cv2.resize(img_draw, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    out_img = cv2.resize(out_img, (int(height/4),int(width/4)), interpolation=cv2.INTER_CUBIC)
    cv2.namedWindow('Image')
    cv2.imshow("Image",image)
    cv2.imshow('img_draw', img_draw)
    cv2.imshow('Out Image', out_img)
    cv2.waitKey(0)

cv2.destroyAllWindows()