question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cv2 output different in c# and python

See original GitHub issue

Summary of your issue

Environment

.NET OPENCVSHARP4.WINDOWS

What did you do when you faced the problem?

In Python cv2.imread() got a output : [[42. 49. 58.] [40. 47. 56.] [36. 43. 52.] but in c# I got a output :

63.00,82.00,95.00 61.00,83.00,95.00 77.00,97.00,114.00 first 3 row output (and other output also different)

I don’t know why this happend …

When I tried to other project it was same but now it’s different

Example code:

python : def read_image_bgr(path):

image = cv2.imread(path) #수
print(image[0,:])
return  image 

c#: Mat img1 = Cv2.ImRead(path); img1.ConvertTo(img1, MatType.CV_32FC3); PrintDataMat(img1);

Output:

n Python cv2.imread() got a output : [[42. 49. 58.] [40. 47. 56.] [36. 43. 52.] but in c# I got a output :

63.00,82.00,95.00 61.00,83.00,95.00 77.00,97.00,114.00

What did you intend to be?

I wanted to get same output but it’s different I guess to try to change x axis and y axis but it’s not same … why it is happend …

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
netilovefm1commented, Oct 5, 2020
    public void PrintDataMat(Mat m)
    {
        unsafe
        {
            for (int y = 0; y < m.Size().Height; y++)
            {
                var p = m.Ptr(y); // 높이 0에서 가지는 bgr값
                var ptr = (float*)p.ToPointer();
                if (y == 1) break;
                for (int x = 0; x < m.Size().Width * 3; x += 3)
                {
                    if (x < 7 || x >= 1266) { Console.WriteLine($"{ptr[x]:f},{ptr[x + 1]:f},{ptr[x + 2]:f}"); }
                    
                }
            }
        }
    }

this is PrintDataMat first 3 col and last 4col(i mean 0 1 2 423 424 425 426
bgr bgr bgr bgr bgr bgr bgr)

becasue python print(image) shows only first 3col and last 3col so I make if like that and I tried to use mat.At too … but got a same output

jpeg file size is 426x426 and I think python’s output is correct because when I using jpeg color viewer in online got a same output with python

python version image crop0

0reactions
netilovefm1commented, Oct 5, 2020

ah sorry was my mistake my source was corrupted thanks I close my issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different results in c++ and python openCV code
It seems like i wrote the same things in pyhton and c++, but it produces completely different result. c++ code
Read more >
Different output from Python and C++ in CalibrateHandEye()
Hi, We have tried to translate a C++ project into Python. The problem is that we get different outputs from the calibrateHandEye() function...
Read more >
Different behavior of resize function with python and C++ ...
I am using both opencv 3.4 for python and C platforms. And the behavior of python cv2.resize function does not change between different...
Read more >
Read, Display and Write an Image using OpenCV
Reading, displaying, and writing images are basic to image processing and computer vision. Even when cropping, resizing, rotating, or applying different ...
Read more >
Reading an image in OpenCV using Python
Let's start reading an image. using cv2. To read the images cv2.imread() method is used. This method loads an image from the specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found