Debug simple OpenCV issue in Managed C++

Hi there,

I am opening a bmp image and converting it into CV::MAT format (opencv) . And then write that image into disk. Following is the code I am using. If I am using grayscale image, the writing to disk is working fine. If I am using a color image I am getting a memory access violation. Can you please let me know how to fix this?

Bitmap^ sourceBMP;

sourceBMP = gcnew Bitmap("C:/opencv/[url removed, login to view]", true);

//sourceBMP = gcnew Bitmap("C:/opencv/[url removed, login to view]", true);

cv::Mat cvImg, cvImg_out;

System::Drawing::Rectangle rect = System::Drawing::Rectangle(0, 0, sourceBMP->Width, sourceBMP->Height);

bmp_Depth = System::Drawing::Bitmap::GetPixelFormatSize(sourceBMP->PixelFormat);

bmp_BitsPerPixel = bmp_Depth / 8;

bitmapData = sourceBMP->LockBits(rect, System::Drawing::Imaging::ImageLockMode::ReadWrite, sourceBMP->PixelFormat);

stride = Math::Abs(bitmapData->Stride);

if (bmp_Depth == 8) cvImg = cv::Mat(sourceBMP->Height, stride, CV_8UC1, (char*)bitmapData->[url removed, login to view]());

if (bmp_Depth == 24) cvImg = cv::Mat(sourceBMP->Height, stride, CV_8UC3, (char*)bitmapData->[url removed, login to view]());

cv::imwrite("C:/opencv/[url removed, login to view]", cvImg);

if (bmp_Depth == 24)


cv::cvtColor(cvImg, cvImg_out, CV_BGR2XYZ);

cv::imwrite("C:/opencv/[url removed, login to view]", cvImg_out);


Beceriler: C++ Programlama

Daha fazlasını gör: writing in math, writing height, math programming, math in programming, math and programming, c programming char, char in c programming, char c programming, simple data entry anyone can, jquery issue simple project, simple latex presentation template can add company logo, can convert access database web application, can fit website joomla wrapper width, can backup access database vbnet, can convert access database exe, can convert access 2007 exe, can button access search record, can let users edit xml file server

İşveren Hakkında:
( 108 değerlendirme ) United States, Korea, Republic of

Proje NO: #9774891



Hello. I am a senior level developer and Visual C++ expert. Can you please provide both a grayscale and color image that induces the memory access violation you're seeing? If so, I'm confident I can identify your probl Daha Fazla

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% USD
(1 Yorum)

Bu iş için 9 freelancer ortalamada $28 teklif veriyor


Hello. I have quite large experience with C++/CLI. I would prefer to use drawing instead copying of bits

in %bids___i_period_sub_35% gün içinde26%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(640 Değerlendirme)

Hi! I am professional C/C++/C#/Java/Python programmer! I can do this project with highest quality! Best regards, Szymszteinsl

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(51 Değerlendirme)

Hi! Sir. We are a team of the professional image processing and computer vision development. We have the experience in image processing and OpenCV for 5 years. We have already developed the several image processing Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(13 Değerlendirme)

Hello there, Open CV is only meant (or built ) for native C++ on Windows platforms; not managed C++. Given the sheer amount of pointers and low-lelve C and C+= features used by OpenCV, I'm not at all surprised that Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(1 Yorum)

---------------------------------Best Result on Time-------------------------------------------- Hello! I read your description carefully. Your project is absolutely wonderful and fascinating. I have rich experie Daha Fazla

in %bids___i_period_sub_35% gün içinde106%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(8 Değerlendirme)

Hi, i also work with OpenCV. I'll fix it for you immediately, chat for more information.

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)

Hello, sir, I am image processing expert, i have full experience in opencv. I can solve this problem in 1 hours. Thank you

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)

A proposal has not yet been provided

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)

I guess (without even installing opencv because compiling it is such a pain) that your colour bitmaps are in RGBA (this is semi standard for .bmp) which means you have 3 colour channels plus an alpha channel. Which mea Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)