Zaktualizuj 'examples/example_win32_directx11/main.cpp'
This commit is contained in:
parent
a0c682dc70
commit
46ee5c27a9
@ -423,6 +423,20 @@ void binaryTransform(unsigned char* grayscaleImage, unsigned char* binaryImage,
|
||||
}
|
||||
}
|
||||
|
||||
//void binaryTransform(const unsigned char* image, unsigned char* binaryImage, int threshold, int width, int height, int channels)
|
||||
//{
|
||||
// for (int i = 0; i < width * height; i++) {
|
||||
// unsigned char brightness = 0.2126f * image[i * channels] + 0.7152f * image[i * channels + 1] + 0.0722f * image[i * channels + 2];
|
||||
//
|
||||
// if (brightness < threshold) {
|
||||
// binaryImage[i] = 0;
|
||||
// }
|
||||
// else {
|
||||
// binaryImage[i] = 255;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
int calculateOtsuThreshold(const unsigned char* image, int width, int height) {
|
||||
|
||||
int histogram[256] = {0};
|
||||
@ -465,11 +479,11 @@ int calculateOtsuThreshold(const unsigned char* image, int width, int height) {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
void hough_transform(unsigned char* input_image, int width, int height, int threshold)
|
||||
void hough_transform(const unsigned char* input_image, int width, int height, int threshold, unsigned char* hough_image, int channel)
|
||||
{
|
||||
int hough_width = 2 * (width + height);
|
||||
int hough_height = 180;
|
||||
int* hough_space = new int[hough_width * hough_height]();
|
||||
int* hough_space = new int[hough_width * hough_height];
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
@ -497,7 +511,7 @@ void hough_transform(unsigned char* input_image, int width, int height, int thre
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char* hough_image = new unsigned char[hough_width * hough_height * 3]();
|
||||
hough_image = new unsigned char[hough_width * hough_height * channel];
|
||||
for (int y = 0; y < hough_height; y++)
|
||||
{
|
||||
for (int x = 0; x < hough_width; x++)
|
||||
@ -508,6 +522,7 @@ void hough_transform(unsigned char* input_image, int width, int height, int thre
|
||||
hough_image[3 * (y * hough_width + x) + 2] = value;
|
||||
}
|
||||
}
|
||||
delete[] hough_space;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
@ -622,8 +637,9 @@ int main(int, char**)
|
||||
int my_image_height = 0;
|
||||
int my_image_channels = 0;
|
||||
unsigned char* image_data = ImageData(image_location, my_image_width, my_image_height, my_image_channels);
|
||||
unsigned char* grayscaleImage = new unsigned char[my_image_width * my_image_height];
|
||||
unsigned char* binaryImage = new unsigned char[my_image_width * my_image_height];
|
||||
unsigned char* grayscaleImage = new unsigned char[my_image_width * my_image_height * my_image_channels];
|
||||
unsigned char* binaryImage = new unsigned char[my_image_width * my_image_height * my_image_channels];
|
||||
unsigned char* hough_image = nullptr;
|
||||
if (colorR == NULL && colorB == NULL && colorG == NULL) {
|
||||
colorR = new int[256];
|
||||
colorG = new int[256];
|
||||
@ -665,7 +681,7 @@ int main(int, char**)
|
||||
}
|
||||
if (hough)
|
||||
{
|
||||
hough_transform(image_data, my_image_width, my_image_height, calculateOtsuThreshold(image_data, my_image_width, my_image_height));
|
||||
hough_transform(image_data, my_image_width, my_image_height, 125, hough_image, my_image_channels);
|
||||
}
|
||||
if (histogram)
|
||||
{
|
||||
@ -699,6 +715,11 @@ int main(int, char**)
|
||||
delete[] grayscaleImage;
|
||||
stbi_image_free(image_data);
|
||||
}
|
||||
else if (hough == TRUE) {
|
||||
bool ret = LoadTextureFromFile(hough_image, my_image_width, my_image_height, &my_texture);
|
||||
delete[] hough_image;
|
||||
stbi_image_free(image_data);
|
||||
}
|
||||
else {
|
||||
bool ret = LoadTextureFromFile(image_data, my_image_width, my_image_height, &my_texture);
|
||||
stbi_image_free(image_data);
|
||||
|
Loading…
Reference in New Issue
Block a user