मुझे एक 8-बिट IplImage को 32-बिट्स IplImage में कनवर्ट करने की आवश्यकता है। पूरे वेब से दस्तावेज़ीकरण का उपयोग करके मैंने निम्नलिखित चीजों को आजमाया है:एक 8-बिट OpenCV IplImage * को 32-बिट IplImage * में कैसे परिवर्तित करें?
// general code
img2 = cvCreateImage(cvSize(img->width, img->height), 32, 3);
int height = img->height;
int width = img->width;
int channels = img->nChannels;
int step1 = img->widthStep;
int step2 = img2->widthStep;
int depth1 = img->depth;
int depth2 = img2->depth;
uchar *data1 = (uchar *)img->imageData;
uchar *data2 = (uchar *)img2->imageData;
for(h=0;h<height;h++) for(w=0;w<width;w++) for(c=0;c<channels;c++) {
// attempt code...
}
// attempt one
// result: white image, two red spots which appear in the original image too.
// this is the closest result, what's going wrong?!
// see: http://files.dazjorz.com/cache/conversion.png
((float*)data2+h*step2+w*channels+c)[0] = data1[h*step1+w*channels+c];
// attempt two
// when I change float to unsigned long in both previous examples, I get a black screen.
// attempt three
// result: seemingly random data to the top of the screen.
data2[h*step2+w*channels*3+c] = data1[h*step1+w*channels+c];
data2[h*step2+w*channels*3+c+1] = 0x00;
data2[h*step2+w*channels*3+c+2] = 0x00;
// and then some other things. Nothing did what I wanted. I couldn't get an output
// image which looked the same as the input image.
जैसा कि आप देखते हैं कि मैं वास्तव में नहीं जानता कि मैं क्या कर रहा हूं। मुझे पता लगाना अच्छा लगेगा, लेकिन अगर मैं इसे सही तरीके से कर सकता हूं तो मैं इसे और अधिक पसंद करूंगा। मुझे प्राप्त होने वाली किसी भी मदद के लिए धन्यवाद!
उस पृष्ठ पर कुछ रोचक जानकारी नहीं है, कोड के टुकड़े जो समझाने मैं क्या है पहले से ही कोशिश की गई है। परिणाम वही हैं, हालांकि, हर समय गलत क्या है इसके उदाहरण के लिए निम्न लिंक देखें: http://files.dazjorz.com/cache/conversion.png – sgielen
व्हाओ, हाँ, यह एक है अच्छा है, आप सही हैं! तो यह निम्नलिखित सुराग देता है: लाल धब्बे के लिए, आर 1.0 है और जीबी 0.0 है, और सफेद के लिए, सभी तीन 1.0 हैं। इसलिए कनवर्ट करते समय, आरजीबी मूल्यों को शांत करता है डी 0 से 255 से 0.0 से 1.0 में परिवर्तित किया जा सकता है। बी/255 में मूल्य बदलना छवि को काला + लाल बनाता है। – sgielen
समझ गया! int b = ((uchar *) (img-> imageData + h * img-> widthStep)) [w * img-> nChannels + 0]; // बी ((फ्लोट *) (img2-> imageData + h * img2-> widthStep)) [w * img2-> nChannels + 0] = ((float) b)/255.0; – sgielen