How do I get Python BRISQUE package score to match OpenCVSharp BRISQUE score

108 views Asked by At

My goal is to get the BRISQUE score from OpenCVSharp to match the BRISQUE score from Python OpenCV BRISQUE for the same image. The problem is the two platforms take different and incompatible format inputs for the model and range files, and I haven't been able to figure out how to convert one to the other. OR where the Python data originated, so I can obtain it in the format compatible with OpenCVSharp (yml). Can anyone point me in the right direction?

More details:

In Python, the OpenCV library takes a "model" and "norm" file, supplied with the OpenCV package and named "svm.txt" and "normalize.pickle" respectively. These are specified in opencv-env2\Lib\site-packages\brisque\brisque.py. The files are stored in *opencv-env2\Lib\site-packages\brisque\models*.

For OpenCVSharp I'm using the model and range files, in yml format, found here. These are specified in the C# call to QualityBRISQUE.Compute()

The Python and OpenCVSharp model files are clear text, and while the format between them is very different, they both appear to contain the same type of data, and the numerical values are clearly different. So I need to somehow convert the Python version to match the yml format used by OpenCVSharp.

For the range file required by OpenCVSharp; I'm guessing the normalize.pickle file must be the corresponding file on the Python side, but it's some sort of binary format, vs. the text format yml range file used by OpenCVSharp, so I have no idea what to do with that one.

I'm new to OpenCV, and any information or nudge in the right direction would be greatly appreciated!


Edit --> Adding example code:

The following calculates the BRISQUE score in Python:

import cv2
from brisque import BRISQUE

iobj = BRISQUE(url=False)         

Iin = cv2.imread("c:\\temp\\temp.jpg");
score = int(iobj.score(Iin))
print("Score is " + str(score))

In C#, add the Nuget packages OpenCvSharp4, OpenCvSharp4.runtime.win and OpenCvSharp4.Windows, then do this:

static void Main(string[] args)
{
    const string modelFile = "OpenCVSharp\\brisque_model_live.yml";
    const string rangeFile = "OpenCVSharp\\brisque_range_live.yml";
    Mat img = Cv2.ImRead("c:\\temp\\temp.jpg", ImreadModes.AnyColor);
    
    Scalar scoreScaler = QualityBRISQUE.Compute(img, modelFile, rangeFile);
    double score = scoreScaler[0];
    
    Console.WriteLine("Score: " + score.ToString());
}

Using the image found here, Python gives a score of 59, C# gives a score of 37.6.

0

There are 0 answers