Opencv learning notes 1, (tbb_debug error, learning opencv examples 2-1, 2-2, 2-3, 2-4, 2-5, 2-6, 2-7, 2-8, 22-9, 2-0)

Source: Internet
Author: User
Opencv experiences (1)

The second chapter of learning opencv mainly introduces some common and interesting functions and data types, so that students at the beginning are more interested in image processing, although I do not understand the internal experiment of the function and the meaning of some defined constants, I am still very happy after learning Chapter 2. At least I know some basics of image processing, such as contour processing;

Knowledge point:

A) image channels:

1 channel refers to grayscale images,

3. The channel refers to the image of the RGB combination.

Channel 4 adds the transparency proposed by Microsoft on the basis of Channel 3.

B) smooth image processing: Make the lines smoother.

C) Image Scaling: Unfortunately, only two times of scaling can be performed now.

D) image contour processing: displays the image contour.

E) The CV header file contains a lot of image processing software.

F) The highgui. h header file contains functions such as image acquisition and output.

G) Prompt tbb_debug error, if the machine is 64 for, and opencv Chinese forum in the method is not good, then you can try this link in the method: http://download.csdn.net/detail/threedonkey/4228886

 

The following is an example in the book.

/* Display the content in the camera */# include <opencv \ highgui. h> # include <windows. h> int main (INT argc, tchar * argv []) {int C; // allocate memory for an imageiplimage * IMG; // capture from Video device # 1cvcapture * capture = cvcapturefromcam (0); // create a window to display the imagescvnamedwindow ("mainwin", cv_window_autosize ); // position the windowcvmovewindow ("mainwin", 5, 5); While (1) {// retrieve the captured frameimg = cvqueryframe (capture ); // show the image in the windowcvshowimage ("mainwin", IMG); // wait 10 MS for a key to be pressedc = cvwaitkey (10 ); // escape key terminates programif (C = 27) break;} return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/* Get an image and display the window */INT main (INT argc, char ** argv) {// define an image class, obtain the image iplimage * IMG = cvloadimage ("_ u00002iu1 ~ S] UA ~ Yq1_p5la0i.jpg ");//? // Create a window with the size automatically aligned with the image cvnamedwindow ("donkeyaime", cv_window_autosize); // display the image cvshowimage ("donkeyaime", IMG) in the window ); // wait for the user to enter any key to end cvwaitkey (0); // release the space cvreleaseimage (& IMG); // close the window cvdestroywindow ("donkeyaime"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/* Obtain a video file and display it in the window */# include <opencv \ highgui. h> # include <windows. h> int main () {// create a window cvnamedwindow ("donkeyaime", cv_window_autosize); // obtain the AVI file. The capture points to the file header cvcapture * capture = cvcreatefilecapture ("car. avi "); iplimage * frame; while (1) {// frame receives the current frame information in the capture structure and updates the structure information. The frame does not need to open up memory, the cvcapture struct has been allocated with memory. Frame = cvqueryframe (capture); If (! Frame) break; // display the image to cvshowimage ("donkeyaime", frame) in the window just now; // wait for 33 Ms user input, enter ESC, c = 27, if there is no input, C is-1 char c = cvwaitkey (33); If (C = 27) break;} // release the memory applied by the struct, close the opened file handle cvreleasecapture (& capture); // close the window cvdestroywindow ("donkeyaime"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/* Read a video file, display it in the window, and add the scroll bar function */# include <opencv \ highgui. h> # include <opencv \ cv. h> // defines the position of the scroll bar and the cvcapture object. Because it is global, add g _ to distinguish int g_slider_position = 0; cvcapture * g_capture = NULL; // call this function automatically when dragging the scroll bar. Void ontrackbarslide (int pos) {// cvsetcaptureproperty sets the attribute of the cvcapture object. // cv_cap_prop_pos_frames indicates that the cvsetcaptureproperty (g_capture, Clip) is used, pos);} int main () {cvnamedwindow ("donkeyaime", c V_window_autosize); g_capture = cvcreatefilecapture ("car. avi "); // cvgetcaptureproperty get the cvcapture Object Property // frames get the total number of video frames int frames = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_frame_count); If (frames) {// cvcreatetrackbar sets the scroll bar information, name, window, position, upper position, and callback function cvcreatetrackbar ("position", "donkeyaime", & g_slider_position, frames, ontrackbarslide );} iplimage * frame; while (1) {// frame receives the current frame in the capture struct And update the struct information. The frame does not need to open up memory. The cvcapture struct has been allocated with memory. Frame = cvqueryframe (g_capture); If (! Frame) break; // display the image to cvshowimage ("donkeyaime", frame) in the previous window; // move the scroll bar forward to cvsettrackbarpos and set the position of the scroll bar g_slider_position ++; cvsettrackbarpos ("position", "donkeyaime", g_slider_position); // wait for user input in MS, input is ESC, c = 27, no input, C is-1 char c = cvwaitkey (33); If (C = 27) break;} // release the memory applied by the struct, close the opened file handle cvreleasecapture (& g_capture); // close the window cvdestroywindow ("donkeyaime"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/* Perform Gaussian smoothing on the image */# include <opencv/highgui. h> # include <opencv/cv. h> void exp2_4 (iplimage * image) {// create two new windows: cvnamedwindow ("donkeyaime_in"); cvnamedwindow ("donkeyaime_out"); cvshowimage ("donkeyaime_in", image ); // create an extension object and set its image structure space iplimage * out = cvcreateimage (cvgetsize (image), ipl_depth_8u, 3 ); // perform Gaussian Image Smoothing (cvsmooth (image, out, cv_gaussian, 3, 3); cvshowimage ("donkeyaime_out", out) on the 3*3 area around each pixel of the image ); cvreleaseimage (& out); cvwaitkey (0); cvdestroywindow ("donkeyaime_in"); cvdestroywindow ("donkeyaime_out");} int main () {iplimage * IMG; IMG = cvloadimage ("me.bmp"); exp2_4 (IMG); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/*************************************** * ******************************** // * Resize the image, it can only scale by 2x link * // * Document link: * // * http://www.opencv.org.cn/index.php/Cv%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86#PyrDown *//******************************** **************************************** /# include <opencv/highgui. h> # include <opencv/cv. h> # include <cstdio> void dopyrdown (iplimage * In, int filter = ipl_gaussian_5x5) {// assert macro. When the conditions in the brackets are not met, exit the program, report error assert (in-> width % 2 = 0 & in-> height % 2 = 0); // create an iplimage object and initialize the object space, is the original image 1/2iplimage * out = cvcreateimage (cvsize (in-> width/2, in-> height/2), in-> depth, in-> nchannels ); // call the function to scale the image. The function belongs to the CV. h image processing cvpyrdown (In, out, filter); cvnamedwindow ("donkeyaime_out", cv_window_autosize); cvshowimage ("donkeyaime_out", out); cvwaitkey (0 );} void dopyrup (iplimage * In, int filter = ipl_gaussian_5x5) {iplimage * out = cvcreateimage (cvsize (in-> width * 2, in-> height * 2 ), in-> depth, in-> nchannels); cvpyrup (In, out, filter); cvnamedwindow ("donkeyaime_out", cv_window_autosize); cvshowimage ("donkeyaime_out", out ); cvwaitkey (0);} int main () {iplimage * IMG; cvnamedwindow ("donkeyaime_in", cv_window_autosize); IMG = cvloadimage ("me.bmp"); cvshowimage ("donkeyaime_in ", IMG); dopyrup (IMG); cvwaitkey (0); cvreleaseimage (& IMG); cvdestroywindow ("donkeyaime_in"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/*************************************** * **********************************// * The edge processing of the canny Image, you can only use the * // * canny In the CV header file for Grayscale Images *//*********************** **************************************** * ********/# include <cstdio> # include <opencv \ highgui. h> # include <opencv \ cv. h> # define low 500 # define high 501 // The function is to detect the image edge according to the input valve value iplimage * Dokan (iplimage * In, double lowthresh, double highthresh, double aperture) {If (in-> nchannels! = 1) return 0; iplimage * out = cvcreateimage (cvgetsize (in), ipl_depth_8u, 1); cvkan (In, out, lowthresh, highthresh, aperture); Return out ;} int main () {iplimage * IMG, * out1, * out2; cvnamedwindow ("donkeyaime_in", cv_window_autosize); cvnamedwindow ("temperature", cv_window_autosize); namcvedwindow ("temperature ", cv_window_autosize); // parameter 0 indicates converting the read image to a single-channel image IMG = cvloadimage ("me.bmp", 0); cvshowimage ("donkeyaime_in", IMG ); out1 = Dokan (IMG, 0, 1, 3); out2 = Dokan (IMG, low, high, 3); cvshowimage ("donkeyaime_out1", out1 ); cvshowimage ("outputs", out2); cvwaitkey (0); cvreleaseimage (& IMG); cvreleaseimage (& out1); cvreleaseimage (& out2); cvdestroywindow ("donkeyaime_in "); cvdestroywindow ("doukeyaime_out1"); cvdestroywindow ("donkeyaime_out2"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/*************************************** * ******************************** // * The image scales 4 times then, perform the cvkan edge processing *//******************************** **************************************** /# include <opencv \ highgui. h> # include <opencv \ cv. h ># include <cstdio> iplimage * dopyrdown (iplimage * In, int filter = cv_gaussian_5x5) {iplimage * out; printf ("% d \ n ", in-> width, In-> height); Assert (in-> width % 2 = 0 & in-> heigh T % 2 = 0); out = cvcreateimage (cvsize (in-> width/2, in-> height/2), in-> depth, in-> nchannels ); cvpyrdown (In, out, filter); Return out;} iplimage * Dokan (iplimage * In, double lowthresh, double highthresh, double aperture) {If (in-> nchannels! = 1) return 0; iplimage * out = cvcreateimage (cvgetsize (in), in-> depth, in-> nchannels); cvkan (In, out, lowthresh, highthresh, aperture); Return out;} int main () {iplimage * IMG, * out; cvnamedwindow ("donkeyaime_in", cv_window_autosize); cvnamedwindow ("donkeyaime_out", cv_window_autosize ); IMG = cvloadimage ("me1.jpg", 0); cvshowimage ("donkeyaime_in", IMG); out = dopyrdown (IMG, cv_gaussian_5x5); out = dopyrdown (Out, timeout ); out = Dokan (Out, 10,100, 3); cvshowimage ("donkeyaime_out", out); cvwaitkey (0); cvreleaseimage (& IMG); cvreleaseimage (& out ); cvdestroywindow ("donkeyaime_in"); cvdestroywindow ("donkeyaime_out"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/*************************************** *********************************** // You can input a video from a camera, and perform edge processing *//********************************* ***************************************/ # include <opencv \ highgui. h> # include <opencv \ cv. h> iplimage * Dokan (iplimage * In, double lowthresh, double highthresh, double aperture) {If (in-> nchannels! = 1) return 0; iplimage * out = cvcreateimage (cvgetsize (in), ipl_depth_8u, 1); cvkan (In, out, lowthresh, highthresh, aperture); Return out ;} int main () {cvcapture * capture; capture = cvcreatecameracapture (0); Assert (capture! = NULL); iplimage * frame, * framechange; cvnamedwindow ("donkeyaime_in"); cvnamedwindow ("donkeyaime_out"); While (1) {frame = cvqueryframe (capture ); // The image must be converted to a grayscale image framechange = cvcreateimage (cvgetsize (FRAME), frame-> depth, 1); cvcvtcolor (frame, framechange, cv_bgr2gray); framechange = Dokan (framechange, 10,100, 3); cvshowimage ("donkeyaime_in", frame); cvshowimage ("donkeyaime_out", framechange); char c = cvwaitkey (33); If (C = 27) break;} cvreleasecapture (& capture); cvdestroywindow ("donkeyaime_in"); cvdestroywindow ("donkeyaime_out"); Return 0 ;}

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////

/*************************************** * ********************************** Read a video file, after some conversions, write them into the video file again. * // * unfortunately, I guess there is no encoder, after writing the video, you cannot watch *//****************************** **************************************** **/# include <opencv \ highgui. h> # include <opencv \ cv. h> int main () {cvcapture * capture = 0; capture = cvcreatefilecapture ("car. avi "); If (! Capture) Return-1; iplimage * bgr_frame = cvqueryframe (capture); double FPS = cvgetcaptureproperty (capture, cv_cap_prop_fps); cvsize size = cvsize (INT) cvgetcaptureproperty ), (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_height); cvvideowriter * Writer = cvcreatevideowriter ("car. avi ", cv_fourcc ('M', 'J', 'P', 'G'), FPS, size); iplimage * logpolar_frame = C Vcreateimage (size, ipl_depth_8u, 3); While (bgr_frame = cvqueryframe (capture ))! = NULL) {cvlogpolar (bgr_frame, logpolar_frame, cvpoint2d32f (bgr_frame-> width/2, bgr_frame-> height/2), 40, cv_inter_linear + distance); cvwriteframe (writer, logpolar_frame);} cvreleasevideowriter (& writer); cvreleaseimage (& logpolar_frame); cvreleasecapture (& capture); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.