| | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | | #include "opencv2/imgproc/imgproc_c.h" |
| | | #include "opencv2/core/types_c.h" |
| | | #include "opencv2/core/version.hpp" |
| | | #ifndef CV_VERSION_EPOCH |
| | | #include "opencv2/videoio/videoio_c.h" |
| | |
| | | return r; |
| | | } |
| | | |
| | | static float get_pixel(image m, int x, int y, int c) |
| | | { |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | return m.data[c*m.h*m.w + y*m.w + x]; |
| | | } |
| | | static float get_pixel_extend(image m, int x, int y, int c) |
| | | { |
| | | if (x < 0 || x >= m.w || y < 0 || y >= m.h) return 0; |
| | | /* |
| | | if(x < 0) x = 0; |
| | | if(x >= m.w) x = m.w-1; |
| | | if(y < 0) y = 0; |
| | | if(y >= m.h) y = m.h-1; |
| | | */ |
| | | if (c < 0 || c >= m.c) return 0; |
| | | return get_pixel(m, x, y, c); |
| | | } |
| | | static void set_pixel(image m, int x, int y, int c, float val) |
| | | { |
| | | if (x < 0 || y < 0 || c < 0 || x >= m.w || y >= m.h || c >= m.c) return; |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | m.data[c*m.h*m.w + y*m.w + x] = val; |
| | | } |
| | | static void add_pixel(image m, int x, int y, int c, float val) |
| | | { |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | m.data[c*m.h*m.w + y*m.w + x] += val; |
| | | } |
| | | |
| | | void composite_image(image source, image dest, int dx, int dy) |
| | | { |
| | | int x,y,k; |
| | |
| | | } |
| | | if (class_id >= 0) { |
| | | int width = im.h * .006; |
| | | if (width < 1) |
| | | width = 1; |
| | | |
| | | /* |
| | | if(0){ |
| | |
| | | return im; |
| | | } |
| | | |
| | | image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int use_webcam) |
| | | image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img, int cpp_video_capture) |
| | | { |
| | | IplImage* src; |
| | | if (use_webcam) src = get_webcam_frame(cap); |
| | | if (cpp_video_capture) { |
| | | static int once = 1; |
| | | if (once) { |
| | | once = 0; |
| | | do { |
| | | src = get_webcam_frame(cap); |
| | | if (!src) return make_empty_image(0, 0, 0); |
| | | } while (src->width < 1 || src->height < 1 || src->nChannels < 1); |
| | | } else |
| | | src = get_webcam_frame(cap); |
| | | } |
| | | else src = cvQueryFrame(cap); |
| | | |
| | | if (!src) return make_empty_image(0, 0, 0); |
| | | if (src->width < 1 || src->height < 1 || src->nChannels < 1) return make_empty_image(0, 0, 0); |
| | | IplImage* new_img = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3); |
| | | *in_img = cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U, 3); |
| | | cvResize(src, *in_img, CV_INTER_LINEAR); |
| | | cvResize(src, new_img, CV_INTER_LINEAR); |
| | | image im = ipl_to_image(new_img); |
| | | cvReleaseImage(&new_img); |
| | | if (cpp_video_capture) cvReleaseImage(&src); |
| | | rgbgr_image(im); |
| | | return im; |
| | | } |
| | |
| | | unsigned char *data = stbi_load(filename, &w, &h, &c, channels); |
| | | if (!data) { |
| | | fprintf(stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason()); |
| | | exit(0); |
| | | exit(1); |
| | | } |
| | | if(channels) c = channels; |
| | | int i,j,k; |
| | |
| | | return out; |
| | | } |
| | | |
| | | float get_pixel(image m, int x, int y, int c) |
| | | { |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | return m.data[c*m.h*m.w + y*m.w + x]; |
| | | } |
| | | float get_pixel_extend(image m, int x, int y, int c) |
| | | { |
| | | if(x < 0) x = 0; |
| | | if(x >= m.w) x = m.w-1; |
| | | if(y < 0) y = 0; |
| | | if(y >= m.h) y = m.h-1; |
| | | if(c < 0 || c >= m.c) return 0; |
| | | return get_pixel(m, x, y, c); |
| | | } |
| | | void set_pixel(image m, int x, int y, int c, float val) |
| | | { |
| | | if (x < 0 || y < 0 || c < 0 || x >= m.w || y >= m.h || c >= m.c) return; |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | m.data[c*m.h*m.w + y*m.w + x] = val; |
| | | } |
| | | void add_pixel(image m, int x, int y, int c, float val) |
| | | { |
| | | assert(x < m.w && y < m.h && c < m.c); |
| | | m.data[c*m.h*m.w + y*m.w + x] += val; |
| | | } |
| | | |
| | | void print_image(image m) |
| | | { |
| | | int i, j, k; |