Repository: opencv/opencv
File: modules/python/src2/cv2_convert.cpp (C++)

Code before:
        }
        return true;
    }

    if( !PyArray_Check(o) )
    {
        failmsg("%s is not a numpy array, neither a scalar", info.name);
        return false;
    }

    PyArrayObject* oarr = (PyArrayObject*) o;

    if (info.outputarg && !PyArray_ISWRITEABLE(oarr))
    {
        failmsg("%s marked as output argument, but provided NumPy array "
                "marked as readonly", info.name);
        return false;
    }

    bool needcopy = false, needcast = false;
    int typenum = PyArray_TYPE(oarr), new_typenum = typenum;
    int type = typenum == NPY_UBYTE ? CV_8U :
               typenum == NPY_BYTE ? CV_8S :
               typenum == NPY_USHORT ? CV_16U :
               typenum == NPY_SHORT ? CV_16S :
               typenum == NPY_UINT32 ? CV_32U :
               typenum == NPY_INT32 ? CV_32S :
               typenum == NPY_UINT64 ? CV_64U :
               typenum == NPY_INT64 ? CV_64S :
               typenum == NPY_HALF ? CV_16F :
               typenum == NPY_FLOAT ? CV_32F :
               typenum == NPY_DOUBLE ? CV_64F :
               typenum == NPY_BOOL ? CV_Bool :
               -1;

    if( type < 0 )
    {
        if( typenum == NPY_LONG )
        {
            needcopy = needcast = true;
            new_typenum = NPY_INT;
            type = CV_32S;
        }
        else
        {
            const std::string dtype_name = getArrayTypeName(oarr);
            failmsg("%s data type = %s is not supported", info.name,
                    dtype_name.c_str());
            return false;
        }
    }

Review comment (suggestion):
OpenCV interprets INT as int32, not int64 as it's done everywhere in Python. The patch is breaking change for many users.

Code after:
        }
        return true;
    }

    if( !PyArray_Check(o) )
    {
        failmsg("%s is not a numpy array, neither a scalar", info.name);
        return false;
    }

    PyArrayObject* oarr = (PyArrayObject*) o;

    if (info.outputarg && !PyArray_ISWRITEABLE(oarr))
    {
        failmsg("%s marked as output argument, but provided NumPy array "
                "marked as readonly", info.name);
        return false;
    }

    bool needcopy = false, needcast = false;
    int typenum = PyArray_TYPE(oarr), new_typenum = typenum;
    int type = typenum == NPY_UBYTE ? CV_8U :
               typenum == NPY_BYTE ? CV_8S :
               typenum == NPY_USHORT ? CV_16U :
               typenum == NPY_SHORT ? CV_16S :
               typenum == NPY_INT ? CV_32S :
               typenum == NPY_UINT32 ? CV_32U :
               typenum == NPY_INT32 ? CV_32S :
               typenum == NPY_HALF ? CV_16F :
               typenum == NPY_FLOAT ? CV_32F :
               typenum == NPY_DOUBLE ? CV_64F :
               typenum == NPY_BOOL ? CV_Bool :
               -1;

    if( type < 0 )
    {
        if( typenum == NPY_INT64 || typenum == NPY_UINT64 || typenum == NPY_LONG )
        {
            needcopy = needcast = true;
            new_typenum = NPY_INT;
            type = CV_32S;
        }
        else
        {
            const std::string dtype_name = getArrayTypeName(oarr);
            failmsg("%s data type = %s is not supported", info.name,
                    dtype_name.c_str());
            return false;
        }
    }