opencv 一段代码出错了

显示.exe停止工作,但是去掉那个for循环就可以运行,是ptr<>的使用不当吗
#include
#include
#include

#include

using namespace std;
using namespace cv;

int main()
{
// 读入一张图片

Mat img = imread("F:/vsprogram/projecttest/01.jpg");
// 创建一个名为 "picture"窗口

namedWindow("picture");

//创建一个等大图像
Mat  new_img(img.rows,img.cols,CV_8UC3);
//row 行height
for (int  j= 0; j<img.rows; j++)
{

    for (int i = 0; i < img.cols; i++)
    {
        int y=j;
        int x = i;
        new_img.ptr<float>(y)[x] = img.ptr<float>(j)[i];
    }
}


// 在窗口中显示原画  
imshow("picture", new_img);

// 等待6000 ms后窗口自动关闭 
waitKey(6000);

}

先看是不是指针,数组等越界了,指针是否合法等。

真怀念学opencv的时候

img 是U8C3 的ptr<>里写uchar就行了