コードは正常にコンパイルされましたが、一部のイメージでコードを実行しようとすると次のエラーが発生します。sYSMALLOc:opencvでアサーションエラーが発生しました
malloc.c:3096:sYSMALLOc:アサーション `(old_top ==(((mbinptr)(((チャー*)&((AV) - >ビン[((1) - 1)* 2] )) - __builtin_offsetof(struct malloc_chunk、fd)))))& & old_size == 0)|| ((2 *(sizeof(size_t))) - ))&〜((2 *(sizeof(size_t))) (未定義long)old_end & pagemask)== 0) 'が失敗しました。 中止
私のコードは次のとおりです。
#include "opencv2/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
#include "opencv2/modules/highgui/include/opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
/// Global variables
int const min_BINARY_value = 0;
int const max_BINARY_value = 255;
Mat src, src_gray, new_image;
const char* window_name = "Web Safe Colors";
/**
* @function main
*/
int main(int argc, char** argv)
{
double sum=0, mean=0;
/// Load an image
src = imread(argv[1], 1);
/// Convert the image to Gray
cvtColor(src, src_gray, CV_RGB2GRAY);
/// Create new image matrix
new_image = Mat::ones(src_gray.size(), src_gray.type());
/// Calculate sum of pixels
for(int y = 0; y < src_gray.rows; y++)
{
for(int x = 0; x < src_gray.cols; x++)
{
sum = sum + src_gray.at<Vec3b>(y,x)[0];
}
}
/// Calculate mean of pixels
mean = sum/(src_gray.rows * src_gray.cols);
/// Perform conversion to binary
for(int y = 0; y < src_gray.rows; y++)
{
for(int x = 0; x < src_gray.cols; x++)
{
if(src_gray.at<Vec3b>(y,x)[0] <= mean)
new_image.at<Vec3b>(y,x)[0] = min_BINARY_value;
else
new_image.at<Vec3b>(y,x)[0] = max_BINARY_value;
}
}
/// Create a window to display results
namedWindow(window_name, CV_WINDOW_AUTOSIZE);
imshow(window_name, new_image);
/// Wait until user finishes program
while(true)
{
int c;
c = waitKey(20);
if((char)c == 27)
{ break; }
}
}
あなたは私が問題を特定する助けてくださいことはできますか?
OpenCVでエラーが発生した画像が有効/無効である可能性があります。 – Malkocoglu
new_image.atの代わりに 'new_image.at(y、x)'を使用しています(y、x)[0] '問題を解決した。 –