APPARATUS AND METHOD FOR DETECTING, IDENTIFYING AND INCORPORATING ADVERTISEMENTS IN A VIDEO

Abstract: A system (Figs 7 and 8) and method (Fig 1) for video transmission of active events, for example sports events, having in the background physical images in designated targets, wherein the physical images are electronically exchanged with preselected virtual images, so that objects or shadows actually blocking portions of the physical images will be seen by viewers as blocking the same portions of the virtual images, and the motion of players or a ball blocking the physical image will block corresponding regions of the exchanged virtual image, so that the exchanged electronic image will remain in the background of the event, exactly as the original image.

Description: APPARATUS AND METHOD FOR DETECTING, IDENTIFYING AND INCORPORATING ADVERTISEMENTS IN A VIDEO The present invention relates to apparatus and methods for superimposing a small video image into a larger video image. International sports events or other spectacles generally draw the interest and attention of spectators in many countries. For example, the Olympics, Superbowl, World Cup, major basketball and soccer games, auto races etc. fit into this category. Such events are generally broadcast live by video to a large international audience. The locale in which these events take place, such as stadiums or courts, provide advertising space all around in the form of signs, posters or other displays on fences and billboards, and in fact on any unoccupied space suitably located, including sections of the playing field. Due to the nature of the displays, which are mostly in the form of printed matter, they are not changed too frequently and remain at least for a day, or a series or a whole season, and are directed mostly at local audiences. In cases where two teams from different countries play each other, the advertisements are usually arranged so that one side of the stadium contains advertisements directed to audiences in one country, while the other side has advertisements directed to the spectators in the other country. The video cameras in these instances film the event from opposite sides of the stadium for their respective audiences. This of course is logistically complicated and limits the angle from which the events can be seen in either of the countries represented in the game. Another limitation to present methods of advertising is the stringent safety requirements for positioning the billboards, so as not to interfere with the game, nor disturb the view of the spectators in the stadium, nor pose a danger to the players. The displays must not be too close to the actual field of action, so as not to distract the players. A most serious drawback of the present system for advertising at major world sports events is the fact that although the event is televised live throughout the world, the actual physical advertisements in the stadium, because of their broad international exposure, can only cater to products having a world market. Local advertisers can only make use of such world-class televised events by locally superimposing messages on the TV screen, or by interrupting the real time of the event. Another drawback of the existing system is that over long time periods, due to the scanning of the TV camera, the signs appear too blurred to be read by the TV viewers. On many other occasions, only part of the sign is visible to the TV viewers and the sign cannot be read. The following reference, the disclosure of which is incorporated herein by reference, describes Gaussian edge detection: J.F. Canny, "A computational approach to edge detection", IEEE Trans. Pattern Analysis and Machine Intelligence, Vol. 8, pp. 679-698, November, 1986. -__* The present invention relates to a system and method for detecting, identifying and scaling in a video frame, suitable distinct targets and areas and inserting into these areas virtual images stored in the memory of the system, so that all objects or shadows in front of the distinct areas blocking portions thereof from view will be seen in a video transmission as being in front of and blocking the same portions of the areas containing virtual images. A particular feature of the invention is to operate the system in real time. The invention also provides apparatus for operating the system. The invention is particularly useful for advertising in sports courts. It is an object of the present invention to provide a system and method for video transmission of active events, for example sports events, having in the background physical images in designated targets, wherein the physical images are electronically exchanged with preselected virtual images, so that objects or shadows actually blocking portions of the physical images will be seen by viewers as blocking the same portions of the virtual images, and the motion of players or a ball blocking the physical image will block corresponding regions of the exchanged virtual image, so that the exchanged electronic image will remain in the background of the event, exactly as the original image. In a preferred embodiment of the present invention, the physical image to be substituted is detected, recognized, and located automatically and is replaced within one TV frame so that the original image is not perceptible to the TV viewers. In this embodiment no man is required in the loop during line broadcasting. Since the same physical image may be captured by a plurality of TV cameras deployed in various locations around the court, and each camera usually has a continuous zoom lens, the system is able to detect and identify a certain physical target in all possible spatial orientations and magnifications of the target. The system is also capable of unequivocally identifying the scale and perspective of the physical target and normalizing the implanted virtual image into the same perspective. Another object of the invention is to provide a system and method of implanting in video transmission, virtual images in predetermined "free" background areas generally unsuitable for displaying physical signs, like he sports court itself. In a preferred embodiment of the present invention, the task of detection and identification of these free ares is executed automatically. A further object of the present invention is to automatically identify cases in which the physical billboard appears blurred due to camera scanning or jitter and to replace the blurred sign with a clearer one or to alternatively apply the same blurring degree to the replacing sign so that it will have an appearance similar to its neighboring signs. Yet another object of the present invention is to automatically identify a case in which only a small portion of the billboard is visible in the camera'a field of view and to replace this small portion with the whole image of the original billboard. Still another object of the invention is to automatically identify cases in which the resolution of the captured billboard image is not sufficient for the TV viewers and to electronically replace them with larger virtual billboards so that their message may be conveniently captured by the viewers. Another object of the invention is to perform the implantation described above on a succession of video frames. Yet another object of the invention is to provide the above system and method for electronic exchange or planting of virtual images in real time. A further object of the invention is to provide a system and method for video broadcasting the same event to different populations of viewers in real time, with different electronic messages substituted in the spaces occupied by physical displays. Still another object of the invention is to provide a system and method for utilization of available space in a stadium unused by physical displays for the purpose of advertising by planting therein electronic virtual images during real time broadcasting of an event taking place in a stadium. Still a further object of the invention is to provide apparatus for use in video transmission for exchanging physical images with virtual images or planting virtual images in unused background areas during an event in real time video transmission, without disturbing the actual transmission of the event. In accordance with a preferred embodiment of the present invention, there is provided a system and method for broadcasting active events being captured by a TV camera, wherein virtual images are electronically substituted in or superimposed on targets selected from physical displays and preselected background regions, including an electronic data bank of event locales and targets therein, a memory unit for storing digitized virtual images for substitution in the targets, apparatus for grabbing and digitizing video frames, apparatus for automatic target searching in digitized video frames and for detecting targets therein, apparatus • for localization, verifying and identifying the targets, apparatus for comparing the detected targets with corresponding targets in the data bank, apparatus for scaling and identifying the perspective of the original target and transforming the virtual substitute image into the same scale and perspective, apparatus for real-time video tracking of a detected target throughout a succession of frames, and for the identification of target magnification (zoom) or changes in perspective, apparatus for distinguishing between non-background objects and shadows that block portions of the detected targets, apparatus for electronically transferring the objects and shadows from the original video frame to the substituted frame, apparatus for inserting the electronically transformed virtual image into the video frame substituting the original image in the target without this transformation being perceptible by the viewers, apparatus for receiving and storing virtual images and generating a virtual images data bank, apparatus for generating a locale data bank either prior or during an event (a learning system) and video signal input-output apparatus. For this purpose the system uses a special method for the automatic detection and identification of targets using one or more of the following attributes: - geometry - such as the physical configuration of billboards (rectangular shape or parallel lines attribute) as seen from different angles and magnifications, - texture of slogans and graphics - such as for example in posters, - character recognition, - field or court lines - which serve as references for designating free court areas, - standard objects that have typical shape and texture - such as post, backboard, basket and/or a player's shirt, - colour, and - objects and shadows temporarily blocking portions of the image intended to be exchanged. G The method clearly identifies the subject target at any capturing angle and range and in any zoom state, and preferably in real time, so that the original billboard will not be perceptible to the TV viewers. The method typically identifies, in any frame, a relatively large number of targets (up to 20 targets or more in an extreme case) . Blocking objects and shadows are distinguished from the background image by means of: comparing the detected target (partially blocked) with the same target stored in the system's data bank. The smooth and processed difference image between the two is the image of hidden surfaces which forms a part of the blocking object. This procedure may be implemented also by using correlation windows and identifying a low value of the correlation coefficient as being due to occlusion, motion detection - to identify objects that move with respect to the background, texture and geometric shape - distinguishing a player, ball or shadow from a sign, slogan or graphic image etc., and colour - and shades of colour. The electronic exchange is preferably instant and unnoticeable by the viewer since a perceptible exchange is usually unaccepted by the TV networks. Alternatively, it is possible to continuously "fade" the original image while enhancing the virtual image. False identification of targets and images is preferably avoided. The substituted target should be localized to sub-pixel accuracy so that the replacing target be spatially fixed with respect to the frame during the whole succession of TV frames in which the target is inside the camera's field of view. This accuracy is due to the fact that the human eye is sensitive to sub- pixel motions. The methods preferably employ special parallel and pipelined processing hardware which will allow carrying out simultaneously the large number of operations involved in this process. The method of this invention preferably uses two optional sub-systems: a) Digital Image Converter and Storage Unit consisting of an electro-optical scanner for digital conversion and storage of virtual images, for constructing a memory unit for images such as advertisements. The system may also have the possibility of inputting images such as advertisements in other ways, as by digital interface (magnetic, optical disc, communication link) or video port, and may further include a graphics programme and man- machine interface for designing virtual images (like slogans) "on-the-spot". b) Locale "learning" and storage system - for creating a data bank of targets and fixed objects in locales such as stadiums and fields, including: signs (location, shape, colour and type - one-time, seasonal, etc.), court markers (lines, colour, goal/basket, post) , etc. These two sub-systems can operate off-line or can be part of the basic system. The system can "learn" the details of the court in the course of a live event and create/update its data bank for future use. This can also be done using the trial shots taken before the event starts. The method involves the following steps: When the live or previously recorded video film is being transmitted, the following steps take place: 1) Frame grabbing and digitization - each video frame is grabbed and each pixel value is digitized and stored in system memory, 2) Searching - the captured video frame is scanned to detect either actual physical displays . (like the icons stored in the memory) or background regions suitable for implantation whose specifications have been pre-defined. After detection, suspected targets, i.e. displays, are checked for unequivocal identification. This is accomplished by identification of messages and graphics in the displays, or of colour and texture attributes using standard pattern recognition techniques like edge correlation and region matching methods, character recognition, neutral . network techniques and so on. After the target (display) has been identified and accurately localized, its optical magnification and perspective are computed and the locations of all other stored targets (displays) in the frame are consecutively predicted using the locale's lay-out in the data bank, giving the system positive search clues for additional targets in the same video frame. 3) Blocked surface identification - when a given message area or display region is positively identified in a frame, the target (display) is compared with its properly scaled stored image (icon) and those areas of the display that are temporarily blocked by an object such as by the body of a player, by a ball or a shadow etc. are revealed after proper smoothing and processing of the results. The pixel addresses of these surfaces are stored so that these surfaces will later be superimposed on the substituted image. 4) Scaling, perspective transformation and substitution - when a physical image display or a free location is identified and localized, the memory of the system is searched to find the desired virtual image to be substituted or implanted. The exchanged virtual image (patch) is then first normalized to acquire the proper size and perspective of the original physical image and identified blocked surfaces are then removed, so that the exchanged image looks like a background display or as a painted display on the court. 5) Real-time video tracking - typically a given display is visible for a few second before it moves out of the camera's field of view. The system preferably uses previous frames' information to track a given display throughout this succession of frames. To do that, conventional video tracking techniques, such as edge, centroid or correlation tracking methods, are executed. These methods should incorporate subpixel accuracy estimates. Tracking of players or of the ball can also be instrumental to identify blocking portions in the case where target icons are not stored in the system memory or for implantation in free regions. There is thus provided, in accordance with a preferred embodiment of the present invention, apparatus for advertisement incorporation including a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility, and an advertisement incorporator operative to incorporate, into at least one field, an advertisement whose contents varies over time. Further in accordance with a preferred embodiment of the present invention, the advertisement incorporator includes an advertisement site detector operative to detect at least one advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. Still further in accordance with a preferred embodiment of the present invention, the advertisement incorporator is operative to incorporate an advertisement into at least one field at a partially occluded advertisement site within the sports facility. Still further in accordance with a preferred embodiment of the present invention, the contents of the advertisement varies in accordance with a predetermined schedule. Additionally in accordance with a preferred embodiment of the present invention, the contents of the advertisement varies in accordance with an external input. Further in accordance with a preferred embodiment of the present invention, the advertisement incorporator also includes an audience noise evaluator operative to detect and evaluate a level of noise generated by an audience and to provide a noise level input to the advertisement incorporator and wherein the contents of the advertisement varies in accordance with the noise level input. There is additionally provided, in accordance with a preferred embodiment of the present invention, a method for advertisement incorporation including grabbing and digitizing at least one field representing at least a portion of a sports facility, and incorporating into at least one field, an advertisement whose contents varies over time. f ) The present invention will be understood and appreciated more fully from the following detailed description, taken in conjunction with the drawings and appendices in which: Fig. 1 is a logical flow diagram of the processes and tasks required in accordance with a preferred embodiment of the method of the present invention; Fig. 2 is a block diagram of the basic and sub-system modules in accordance with a preferred embodiment of the present invention; Fig. 3 is a block diagram of a basic processing unit; Fig. 4 illustrates a minimum basic on-line system in accordance with a preferred embodiment of the present invention; Fig. 5 illustrates a minimum basic off-line system in accordance with the invention; Fig. 6 illustrates a system in accordance with a preferred embodiment of the present invention adapted for cable TV application; Fig. 7 is a simplified block diagram of a real time system for advertisement site detection and advertisement incorporation, constructed and operative in accordance with a preferred embodiment of the present invention; Fig. 8 is a simplified block diagram of the parallel processor and controller of Fig. 7; Fig. 9 is a simplified block diagram of an alternative embodiment of a real time system for advertisement site detection and advertisement incorporation; Fig. 10A is a simplified flowchart of a preferred method of operation of the parallel processor and controller of Fig. 7, when only a single advertisement site is to be identified and only a single advertisement is to be incorporated at that site; Fig. 10B is a simplified flowchart of a preferred method of operation of the parallel processor and controller of Fig. 7, when a plurality of advertisement sites is to be identified and a corresponding plurality of advertisements, which may or may not differ in content, is to be incorporated at those sites; Fig. 11 is a simplified flowchart of a preferred method for performing the segmentation step of Figs. 10A and 10B; Fig. 12 is a simplified flowchart of a preferred model matching method for performing the advertisement content identification step of Figs. 10A and 10B; Fig. 13 is a simplified flowchart of a preferred method for performing the localization step of Figs. 10A and 10B; Fig. 14 is a simplified flowchart of a preferred method for performing the tracking step of Figs. 10A and 10B; Fig. 15 is a simplified flowchart of a preferred method for performing the occlusion analysis step of Figs. 10A and 10B; Fig. 16 is a simplified flowchart of a preferred method for performing the advertisement incorporation step of Figs. 10A and 10B; Fig. 17 is a simplified block diagram of camera monitoring apparatus useful in conjunction with the advertisement site detection/incorporation apparatus of Fig. 7; Fig. 18 is a simplified flowchart of a preferred method for processing the output of the occlusion analysis process of Fig. 15 in order to take into account images from at least one off-air camera; Fig. 19 is a simplified flowchart of a preferred method for detecting and tracking moving objects of central interest; and Appendix A is a computer listing of a software implemented non-real time system for advertisement site detection and advertisement incorporation, constructed and operative in accordance with an alternative embodiment of the present invention. l* Referring now to Fig. 1, in a preferred embodiment of the present invention, the system and method are designed to automatically perform the substitution of physical targets with synthetic images in real time, although a simpler version of the invention can be used off-line. When operating the system, the modules required are illustrated in the block diagram of Fig. 2. These include: a basic processing unit; an optional scanner/digitizer used to create the data bank of synthetic images from still pictures; and an optional sub-system composed of a TV camera, digitizer and memory to create the stadium data bank. As was mentioned before, there may be other methods to create the data bank of synthetic images. The locale's (stadium's) data bank may also be created from the trial shots taken before the game starts or even be incrementally built in the course of the game by means of a "learning" process or by using data supplied by the stadium owner, the advertiser or the TV network. Fig. 2 illustrates a block diagram of the apparatus used in the system, wherein 1, 2, ....n are a plurality of TV cameras in different positions, which are the usual TV network cameras, 3 is the basic processing unit described in Fig. 3, sub-system 4 converts and stores synthetic images and sub-system 5 is a "learning" and storage system for event locales and targets therein. The output 6 can be transmitted by cable, optical fiber or wirelessly. It can also be displayed and/or recorded. The basic processing unit required to operate the system in real-time is shown in Fig. 3. This module comprises: a frame grabber for colour image acquisition; IS a plurality of image memories; a fast parallel processor; a program memory; data banks of synthetic images to be substituted and of locale's lay-outs and target icons; a man/machine interface for control and for local display and recording; and an image digital to analog converter. The above apparatus is used to automatically locate in real time in each video frame, suitable areas within a stadium which have physical displays or might be suitable for embodying such displays, and to substitute for such physical displays, or introduce into such areas, virtual images which are stored in the memory of the system to serve as advertisements in the background. These electronic inserted images will be seen by viewers as if they are physical displays located in a stadium and all action taking place in front of the actual physical display will appear to the viewer to be taking place in front of the virtual image as well. Fig. 4 illustrates an on-line system in accordance with an aspect of this invention consisting of a video camera 10, video processing unit 12 and work station 14 that provides the required man/machine interface. Fig. 5 illustrates a basic off-line system in accordance with one aspect of this invention. In this case, a video tape 20, a video cassette recorder or a video disk is the input rather than a TV camera and this is processed by the processing unit 22 and work station 24 to provide a video tape output 26 with substituted images. Fig. 6 illustrates yet another application of the system of this invention, namely a cable TV center. The center 30 receives transmissions from stations 32 and 34. These transmissions are processed by the processing unit 22 and work station 24 and broadcast with substituted advertisements to subscribers from the center 30. Although a preferred system according to this invention superimposes blocking objects and shadows on the virtual images, a less sophisticated and much cheaper system is also intended as part of this invention, and that is a system where virtual images are exchanged for physical without relating to blocking objects. Such a system can be quite useful for substituting images in unblocked regions, for example high up in a stadium. Although a preferred embodiment of the present invention automatically detects and recognizes a given billboard in each TV frame, a less sophisticated system is also intended as part of this invention. In such a less sophisticated system the selection of a given sign to be substituted is done "manually" by a pointer such as a light pen or a cursor (operated by a mouse) with a human operator in the loop. This system is mainly off-line. When it is used on-line in real time it will be very difficult for the operator to perform the pointing task since in a typical scenario the sign is cntinuously visible for only short periods of a few seconds each. In such a mode of operation the replacement will nevertheless be perceptible to the TV viewers. This annoys the spectators and in many cases is not permitted by the TV networks. From the above description of the invention, it is apparent that the system, method and apparatus described above can have many applications. Thus, it is also possible to introduce virtual images, such as slogans or graphic advertisement, on the uniforms of players, particularly when a player is shown in close- up. In such a case, the outline of the player, or at least his shirt or helmet, would be the target for /? implanting a virtual image. Another possible application is the automatic generation of continuous video films showing only sequences wherein specific targets, which have been pre-selected, appear to the exclusion of sequences where these targets do not appear. Such video films can be useful for analyzing and monitoring the activity of specific targets, for example individual players and their performance throughout an entire team game. This enables tracking each individual throughout an entire game without having to replay the entire cassette for each player. Another application of this invention is to generate statistical data of targets such as advertisements, for example the number of times and accumulated period that an advertisement appears on the screen, and to debit acccordingly. The implanted image can be in the form of a fixed, blinking or scrolling image, or it may be an animated film or video clip. Fig. 7 is a simplified block diagram of a real time system for advertisement site detection and advertisement incorporation, constructed and operative in accordance with a preferred embodiment of the present invention. The apparatus of Fig. 7 includes a video input source 100, such as a video camera, video cassette, broadcast, video disk, or cable transmission, which is connected, via a suitable connector, with a field grabber 110, preferably, or alternatively with a frame grabber. Henceforth, use of the term "field grabber" is intended to include frame grabbers. The field grabber 110 provides grabbed and digitized fields to a parallel processor and controller 120, described in more detail below with reference to Fig. 8, which is preferably associated with a video display 130 which provides an interactive indication to a user of advertisement site detection and adver- I tisement incorporation operations of the system. Preferably a light pen 140 is associated with the video display 130. According to an alternative embodiment of the present invention, the system receives an indication from a user of the presence in the field of view of one or more advertisements to be replaced and of the location/s thereof. The user input may, for example, be provided by means of a light pen 140. The indication provided by the user may comprise a single indication of an interior location of the advertisement, such as the approximate center of the advertisement or may comprise two or four indications of two opposite vertices or all four vertices, respectively, of an advertisement to be replaced. Optionally, the user also provides an indication of the contents of the advertisement. For example, a menu of captions identifying advertisements to be replaced, may be provided on the video display 130 adjacent or overlaying a display of the playing field and the user can employ the light pen to identify the appropriate caption. An advertisement images and advertisement arrangement database 150 is provided which may be stored in any suitable type of memory such as computer memory or secondary memory, such as a hard disk. The advertisement image and arrangement database 150 typically stores a plurality of advertisement images, typically still images, including images to be replaced and/or images to be incorporated into the image of the playing field, either replacing an existing advertisement or in a location not presently occupied by an advertisement. The database 150 may also include an indication- of the arrangement of a plurality of advertisements to be replaced, if the arrangement is known ahead of time. Typically, the indication of the arrangement does not include an indication of the location of each advertisement relative to the playing field, but instead includes an indication of the order in which the advertisements to be replaced will be arranged in the field. For example, a sequence of 20 side-by-side advertisements may be arranged around three sides of a playing field. The database 150 may then include an indication of the sequence in which the advertisements are arranged. Advertisement images in the database 150 may be provided by field grabber 110 or from any suitable advertisement image source 160, such as but not limited to an image generating unit such as a image processing workstation, a scanner or other color reading device, any type of storage device, such as a hard disk, a CD ROM driver, or a communication link to any of the above. The video output of the system may be provided via a suitable connector to suitable equipment for providing wireless or cable transmission to viewers. Fig. 8 is a simplified block diagram of the parallel processor and controller 120 of Fig. 7. The parallel processor/controller 120 preferably includes an advertisement site detection/content identification unit 170, a plurality of parallel tracking modules 180, an occlusion analysis and advertisement incorporation unit 190, a video encoder 200 and a controller 210. The advertisement site detection/content identification unit 170 of Fig. 8 may be implemented based on a suitable plurality of suitable image processing boards, such as Ariel Hydra boards, commercially available from Ariel, USA. Each of these preferably incorporates four TMS320C40 digital signal processors, a DRAM of 64 MB, an SRAM of 1 MB, and a VME bus interface. A specially designed coprocessor is preferably added to these boards to perform the segmentation task. The image processing boards are programmed based on the advertisement site detection and content identification methods of Figs. 11 and .12 on which Appendix A is based in part. For example, the appropriate portions of the listing of Appendix A may be converted into Assembler and the resulting code may be loaded into the digital signal processor of the image processing board. Each of parallel tracking modules 180 may be implemented based on one or more image processing boards, such as Ariel Hydra boards, commercially available from Ariel, USA. Each of these preferably incorporates four TMS320C40 digital signal processors, a DRAM of 64 MB, an SRAM of 1 MB, and a VME bus interface. The image processing boards are programmed for parallel operation based on the tracking method of Fig. 14 on which Appendix A is based in part. For example, the appropriate portions of the listing of Appendix A may be converted into Assembler and the resulting code may be loaded into the digital signal processor of the image processing board. The occlusion analysis and advertisement incorporation unit 190 may also be based on one or more texture mapping boards such as the Fairchild's Thru-D boards with the appropriate bus bridges, programmed based on the occlusion analysis and advertisement incorporation methods of Figs. 15 and 16 on which Appendix A is based in part. For example, the appropriate portions of the listing of Appendix A may be converted into Assembler and the resulting code may be loaded into the processor of the texture mapping board. Video encoder 200 is operative to perform D/A conversion. Controller 210 may, for example, comprise a 486 PC programmed based on the control method of Figs. 10A - 10B on which Appendix A is based in part. For example, the appropriate portions of the listing of Appendix A may be Intel 486 PC processor. Fig. 9 is a simplified block diagram of an alternative embodiment of a real time system for advertisement site detection and advertisement incorporation. In the apparatus of Fig. 9, a conventional workstation 212, having its own video display 220 and its own field grabber (not shown) , such as a Silicon Graphics Onyx workstation loaded with a video board and a suitable software, replaces the following units of Fig. 7: field grabber 110, the parallel processor and controller 120 other than ■ the advertisement site detection and content identification unit 170 and tracking modules 180 thereof, the video display, and the database 150. The software for the workstation may be based on the Appendix A implementation of the method of Figs. 10A - 10B, suitably converted into the workstation's environment, however some of the functions of Appendix A are preferably omitted. Specifically: a. the advertisement site detection and tracking functions, corresponding to the segmentation, advertisement content identification and tracking steps 320, 330 and 310 respectively of Figs. 10A - 10B are omitted and are instead implemented in real time by dedicated hardware 230 in Fig. 9; and b. The texture mapping functions (second and third steps of Fig. 16) which preferably form part of the advertisement incorporation function, are preferably omitted and are, instead, performed by the texture mapping functions provided by the workstation itself. The dedicated hardware 230 of Fig. 9 may be similar to the advertisement site detection/content identification unit 170 and parallel tracking modules 180 of Fig. 8. Appendix A is a computer listing of a non- real time software implementation of the present invention which is operative, for example, on a 486 PC in conjunction with a conventional frame grabber such as an Imaging MFG board. The method of Appendix A is 2.2- now described with reference to Figs. 10A - 16. Fig. 10A is a simplified flowchart of a preferred method of operation of the parallel processor and controller 120 of Fig. 7, when only a single advertisement site is to be identified and only a single advertisement image is to be incorporated at that site. # Fig. 10B is a simplified flowchart of a preferred method of operation of the parallel processor and controller 120 of Fig. 7, when a plurality of advertisement sites is to be identified and a corresponding plurality of advertisement images, which may or may not differ in content, is to be incorporated at those sites respectively. The method of Fig. 10B typically includes the following steps, which are similar to the steps of Fig. 10A which are therefore not described separately for brevity: STEP 290: A digitized video field is received from the field grabber 110 of Fig. 1. STEP 300: A decision is made as to whether or not at least one advertisement in the current field was also present in the previous field (and televised by the same camera) . If so, the current field is termed a "consecutive" field and the segmentation, content identification and localization steps 320, 330 and 340 preferably are replaced only by a tracking step 310. If not, the current field is termed a "new" field. If the field is a "consecutive" field, the plurality of advertisements is tracked (step 310), based on at least one advertisement which was present in a previous field, since the present field is a "consecutive" field. If the field is a "new" field, the advertisement site at which an advertisement is to be incorporated is identified in steps 320, 330 and 340. A loop is performed for each advertisement from among the plurality of advertisements to be processed. 2- Preferably, the segmentation and content identification steps 320 and 330 are performed only for the first advertisement processed. In step 320, a pair of generally parallel lines is typically detected and the image of the field is segmented. Specifically, the portion of the field located within the two detected parallel lines, which typically correspond to the top and bottom boundaries of a sequence of advertisements, is segmented from the remaining portion of the field. Typically, the segmentation step 320 is operative to segment advertisements regardless of: their perspective relative to the imaging camera, the zoom state of the imaging camera lens, the location of the advertisement in the field of view (video field), the angular orientation of the imaging camera relative to the ground and the location of the TV camera. The segmentation step 320 is typically operative to identify an empty or occupied advertisement site on a basis other than location, such as but not limited to any of the following, separately or in any combination: a. Geometrical attributes of the advertisement's boundary such as substantially parallel top and bottom boundaries or such as four vertices arranged in a substantially rectangular configuration; b. A color or a combination of colors or a color pattern, which are known in advance to be present in the advertisement image. c. The spatial frequencies band of the advertisement image, which is typically known in advance. Typically, the known spatial frequencies band is normalized by the height of the advertisement which may, for example, be derived by computing the distance between a pair of detected horizontal lines which are known to be the top and bottom boundaries of the advertisement sequence. In step 330, the content of the portion between the two substantially parallel lines is matched to a stored representation of an advertisement to be replaced. Steps 320 and 330 allow advertisement sites to be identified and the content thereof to be matched to a stored model thereof, even if cuts (transitions, typically abrupt, between the outputs of a plurality of cameras which are simultaneously imaging the sports event) occur during the sports event. Typically, at each cut, steps 320 and 330 are performed so as to identify the advertisement within the first few fields of the cut. Until the next cut occurs, the identified advertisement is typically tracked (step 310) . In step 340, the advertisement is localized at subpixel accuracy. Finally, for each advertisement, occlusion analysis is performed (step 350) and the replacing advertisement is incorporated in the advertisement site (step 360) . Alternatively, the occlusion analysis and advertisement incorporation steps are replaced by an advertisement enhancement step in which the existing advertisement is enhanced, using conventional edge sharpening techniques, rather than being replaced. Optionally, a fee accumulation step 362 is performed, typically after occlusion analysis step 350. In the fee accumulation step, a fee for each advertisement is accumulated. The fee may be computed on any suitable basis. For example, the fee may be determined by counting the total amount of time for which the advertisement was displayed and for which at least 50% of the advertisement was unoccluded, and multiplying by a fixed dollar rate per time unit. Alternatively, the proportion of the unoccluded area of the advertisement may be computed for each time interval, such as each second. Optionally, the display time or the sum over time of the displayed area may be adjusted to take into account the game's progress. For example, the display time or the sum over time of the displayed area may be multipled by an externally provided index indicating the tension level of the game during display of the advertisement. High tension level may, for example, mean that the game has gone into overtime or that a significant event, such as a goal, has occurred during display or just before display. Alternatively, the tension level index may be provided by?the system itself. For example, a voice recognition unit may recognize significant words uttered by the sports commentator, such as the word "goal". According to an alternative embodiment of the present invention, the segmentation and advertisement content identification steps 320 and 330 respectively may be omitted if physical landmarks identifying the locations of advertisements to be replaced whose contents is known in advance, are positioned and captured ahead of time in the playing field. Fig. 11 is a simplified flowchart of a preferred method for performing the segmentation step 320 of Figs. 10A and 10B. The method of Fig. 11 preferably includes the following steps: STEP 380: A new field is received and the resolution thereof is preferably reduced since the forgoing steps may be performed adequately at a lower resolution, for example, a low pass filter may be employed to reduce a 750 x 500 pixel field to 128 x 128 pixels. STEP 390: Optionally, the low resolution image is smoothed, e.g. by median filtering or low pass filtering, so as to remove information irrelevant to the task of searching for long or substantially horizontal lines. STEP 400: Edges and lines (two-sided edges) are detected, using any suitable edge detection method such as the Canny method, described by J.F. Canny in "A computational approach to edge detection", IEEE Trans. Pattern Analysis and Machine Intelligence, Vol. 8, pp. 1 679-698, November, 1986. 2 STEP 404: The edges detected in step 400 are 3 thinned and components thereof are connected using 4 conventional techniques of connectivity analysis. The 5 edges are thresholded so as to discard edges having too 6 small a gradient. 7 STEP 408: The edges detected in steps 400 and 8 410 are compared pairwise so as to find strips, i.e. 9 pairs of parallel or almost parallel lines which are 10 relatively long. If there are no such pairs, the method 11 terminates. 12 STEP 412: Find the spatial frequency spectrum 13 within each strip and reject strips whose spatial 14 frequency contents are incompatible with the spatial 15 frequency band expected for advertisements. Typically, 16 the rejection criterion is such that more than one 17 strip, such as 3 or 4 strips, remain. 18 STEP 416: Rank the remaining strips and 19 select the highest ranking strip. The rank assigned to 20 a strip depends on the probability that the strip 21 includes advertisements. For example, the strip in the 22 lowest location in the upper half of the field is given 23 higher rank than strips above it, because the strips 24 above it are more likely to be images of portions of 2.5 the stadium. The lowest located strip is more likely to 26 be the advertisements which are typically positioned 27 below the stadium. 28 Strips adjacent the bottom of the field are 29 given low rank because the advertisements would only be 30 imaged toward the bottom of the video field if the 31 playing field is not being shown at all, which is 2 unlikely. 33 Fig. 12 is a simplified flowchart of a 4 preferred model matching method for performing the 5 advertisement content identification step 330 of Figs. 6 10A and 10B. Alternatively, advertisement content 7 identification may be provided by a user, as described 8 above with reference to Fig. 1. 2X The method of Fig. 12 is preferably performed in low resolution, as described above with reference to step 380 of Fig. 11. The method of Fig. 12 preferably includes the following steps: STEP 420: The forgoing steps 424, 430, 436, 440, 444 and 452 are performed for each almost parallel strip identified in segmentation step 320 of Fig. 11. STEP 424: The distance and angle between the two lines of each strip is computed and the scale and approximate perspective at which the strip was imaged is determined therefrom. STEP 430: During set-up, each advertisement model is divided into a plurality of windows. Steps 436, 440 and 444 are performed for each window of each advertisement model. For example, if there are 5 models each partitioned into 6 windows, this step is performed 30 times. STEP 436: A one-dimensional similarity search is carried out for the suitably scaled current model window k, along the current almost parallel strip. Typically, a cross-correlation function may be computed for each pixel along the current strip. STEP 440: The cross-correlation function values obtained in step 436 are thresholded. For example, values exceeding 0.6 may be assigned the value 1 (correlation) whereas values under 0.6 may be assigned the value 0 (no correlation). The l's are weighted, depending on the "significance" of their corresponding windows. The "significance" of each window is preferably determined during set-up such that windows containing more information are more "significant" than windows containing little information. STEP 444: At this stage, weighted thresholded cross-correlation function values have been computed which represent the results of matching the contents of each position along the strip (e.g. of each of a plurality of windows along the strip which are spaced at a distance of a single pixel) to each window of each model advertisement known to occur within the strip. The weighted thresholded cross-correlation function values are accumulated per all windows composing a model sign or a model strip. STEP 452: A decision is made as to the approximate location of the sequence of advertising models, within the strip. It is appreciated that, once the location of one advertisement model has been determined, the locations of the other advertisemnt models in the same sequence are also determined, knowing the scale ad approximate perspective of the imaged strip. Fig. 13 is a simplified flowchart of a preferred method for performing the precise localization step 340 of Figs. 10A and 10B. In Fig. 13, the advertisement model which was approximately localized by the method of Fig. 12, is localized with subpixel accuracy. Accurate localization is typically performed only for new fields. For "consecutive" fields, the advertisement's location is preferably measured by video tracking. The method of Fig. 13 preferably includes the following steps: STEP 460: From Fig. 12, the following information is available per advertisement detected: one location within the advertisement, such as one vertex thereof, the advertisement scale height in the image and its approximate perpsective. This information is employed to compute the four vertices of each detected advertisement. STEP 464: A perspective transformation is computed which describes how to "transform" the typically rectangular model into the detected advertisement area which is typically non-rectangular due to its pose relative to the imaging camera. STEP 468: The contents of each of a plurality of model tracking windows to which the model is divided during set up, is mapped into the video field, using the perspective transformation computed in step 464. STEP 470: Steps 472 and 476 are performed for each of the model tracking windows. STEP 472: The current model tracking window is translated through a search area defined in the video field. For each position of the model tracking window within the search area, a similarity error function (like cross-correlation or absolute sum of differences) is computed. Typically, the model tracking window has 8 x 8 or 16 x 16 different positions within the search area. STEP 476: The minimum similarity error function for the current model tracking window is found. Preferably, the minimum is found at subpixel accuracy, e.g. by fitting a two-dimensional parabola to the similarity error function generated in step 472 and computing the minimum of the parabola. This minimum corresponds to the best position, at "subpixel accuracy", for the current model tracking window within the video field. If (STEP 480) the similarity error function minima are high for all tracking windows, i.e. none of the tracking windows can be well matched to the video field, then (STEP 482) processing of the current frame is terminated and the method of Fig. 10A, from step 320 onward, is performed on the following frame. STEP 484: Tracking windows which have a high similarity error function minimum are rejected. Typically, approximately 30 tracking windows remain. STEP 488 is a stopping criterion determining whether or not to perform another iteration of localization by matching tracking windows. Typically, if the tracking windows' centers are found to converge, relative to the centers identified in the last iteration, the process is terminated. Otherwise, the method returns to step 464. z ~ 6 STEP 490: Once the tracking window locations have converged, the perspective transformation between the images advertisement and its model is recomputed. Fig. 14 is a simplified flowchart of a preferred method for performing the tracking step 310 of Figs. 10A and 10B. The method of Fig. 14 preferably includes the following steps: STEP 492: A perspective transformation is performed on the model tracking windows and the contents thereof are mapped into the video field. This step employs the system's knowledge of the location of the advertisement in the previous field and, preferably, predicted scanning speed of the camera imaging the sports event. STEP 496: Steps 498 and 500, which may be similar to steps 472 and 476, respectively, of Fig. 13, are performed for each model tracking window. STEPS 508 AND 512 may be similar to steps 488 and 490 of Fig. 13. STEP 510: If the window center locations do not yet converge, step 492 is redone, however, this time, the texture mapping is based upon the perspective transformation of the previous iteration. STEP 520: The coefficients of the perspective transformation are preferably temporally smoothed, since, due to the smoothness of the camera's scanning action, it can be assumed that discontinuities are noise. Fig. 15 is a simplified flowchart of a preferred method for performing the occlusion analysis step 350 of Figs. 10A and 10B. The method of Fig. 15 preferably includes the following steps: STEP 530: The advertisement image in the video field is subtracted from its perspective transformed model, as computed in step 512 of Fig. 14 or, for a new field, in step 390 of Fig. 13. STEP 534: Preferably, the identity of the advertisement image and the stored advertisement is verified by inspecting the difference values computed in step 530. If the advertisement image and the stored advertisement are not identical, the current field is not processed any further. Instead, the next field is processed, starting from step 320 of Fig. 10B. STEP 538: The internal edge effects are filtered out of the difference image computed in step 530 since internal edges are assumed to be artifacts. STEP 542: Large non-black areas in the difference image are defined to be areas of occlusion. STEP 546: The occlusion map is preferably temporally smoothed since the process of occlusion may be assumed to be continuous. Fig. 16 is a simplified flowchart of a preferred method for performing the advertisement incorporation step 360 of Figs. 10A and 10B. The method of Fig. 16 preferably includes the following steps: STEP 560: The resolution of the replacing advertisement model, i.e. the advertisement in memory, is adjusted to correspond to the resolution in which the advertisment to be replaced was imaged. Typically, a single advertisement model is stored in several different resolutions. STEP 570: The replacing advertisement is transformed and texture mapped into the video field pose, using tri-linear interpolation methods. This step typically is based on the results of step 512 of Fig. 14 or, for a new field, on the results of step 390 of Fig. 13. STEP 580: Aliasing effects are eliminated. STEP 590: The replacing pixels are keyed in according to an occlusion map. The values of the replacing pixels may either completely replace the existing values, or may be combined with the existing values, as by a weighted average. For example, the second alternative may be used for edge pixels whereas the first alternative may be used for middle pixels. Fig. 17 is a simplified block diagram of camera monitoring apparatus useful in conjunction with a conventional TV camera and with the advertisement site detection/incorporation apparatus of Fig. 7. If the parallel processor and controller of Fig. 7 is as illustrated in Fig. 8, the apparatus of Fig. 17 is not required and instead, a conventional TV camera may be employed. However, in the alternative, the automatic detection and content identification features of the system may be eliminated, by eliminating unit 170 of Fig. 8. In this case, the apparatus of Fig. 17 is preferably provided in operative association with the TV camera at the stadium or playing field. The apparatus of Fig. 17 provides camera information, including the identity of the "on-air" camera, its lens zoom state and the direction of its FOV center. This information may be employed, in conjunction with known information as to the positions and contents of advertisements in the stadium, in order to detect, identify and even roughly track each advertisement. The apparatus of Fig. 17 includes: (a) a plurality of conventional TV cameras 600 of which one is shown in Fig. 17; (b) for each camera 600, a camera FOV (field of view) center direction measurement unit 610 at least a portion of which is typically mounted on the TV camera 600 pedestal; (c) for each camera 600, a camera lens zoom state monitoring unit 620 which is typically mounted on the TV camera 600 pedestal . The monitoring unit 620 receivse an output indication of the zoom state directly from the zoom mechanism of the camera; (d) an "on-air" camera identification unit 630 operative to identify the camera, from among the plurality of TV cameras 600, which is being broadcast. This information is typically available from the broadcasting system control unit which typically re- ceives manual input selecting an on-air camera, from a 3 . producer; and (e) a camera information video mixer 640 operative, to mix the output of units 610, 620 and 630 onto the broadcast. Any suitable mixing may be employed, such as mixing onto the audio channel, mixing onto the time code, or mixing onto the video signal itself. c The camera FOV direction measurement unit 610 may be implemented using any of the following methods, inter alia: a. On-camera NFM (North Finding Module) in conjunction with two inclinometers for measuring the two components of the local gravity vector angle with respect to the FOV center direction; b. GPS- (Global Position System) based direction measurement system; c. Triangulation - — positioning two RF sources at two known locations in the playing field or stadium and an RF receiver on the camera; d. an on-camera boresighted laser designator in combination with an off-camera position sensing detector operative to measure the direction of the beam spot generated by the lasr designator. Fig. 18 is a simplified flowchart of an optional method for processing the output of the occlusion analysis process of Fig. 15 in order to take into account images from at least one off-air camera. If the method of Fig. 18 is employed, a video compressor and mixer 700 are provided in operative association with the TV cameras which are imaging the event at the playing field or stadium, as shown in Fig. 2. The output of the compressor and mixer 700, comprising compressed images of the playing field as imaged by all of the TV cameras other than the TV camera which is "on-air", blended with the broadcast signal, is broadcast to remote advertisement site detection/incorporation systems such as that illustrated in Fig. 7. The transmission provided by compressor and mixer 700 of Fig. 2 is first decoded and decompressed in step 710 of Fig. 18. STEP 720: Steps 730, 740 and 750 are repeated for each advertisement site imaged by the "on air" camera. STEP 730: Although it is possible to employ information from more than one of the "off-air" cameras, preferably, only a single "off air" camera is employed to process each advertisement site and the single "off-air" camera is selected in step 730. For example, if the apparatus of Fig. 17 is provided, the output of camera FOV direction measurement unit 610 for each "off-air" camera may be compared in order to identify the "off-air" camera whose FOV direction is maximally different from the FOV direction of the "on- air" camera. Alternatively, particularly if the appa- ratus of Fig. 17 is omitted, a single "off-air" camera may be selected by performing preliminary analysis on the images generated by each of the "off-air" cameras in order to select the most helpful "off-air" camera. For example, the images generated by each "off-air" camera may be matched to the stored representation of the advertisement currently being processed. Then, the actual image may be warped and then subtracted from the stored representation for each "off-air" camera in order to obtain an estimate of the occlusion area for that camera and that advertisement. The camera with the minimal occlusion area may then be selected. STEP 740: The advertisement image of the selected "off-air" camera is warped onto the advertisement site as imaged by the "on-air" camera. STEP 750: The warped "off-air" advertisement image is subtracted from the "on-air" image and the difference image is filtered in order to compute the boundary of the occluding object at pixel-level accuracy. According to a preferred embodiment of the present invention, the advertisement to be incorporated 33 in a particular location in the playing field or other locale may vary over time. This variation may be in accordance with a predetermined schedule, or in accordance with an external input. For example, a speech recognition unit may be provided which is operative to recognize key words, such as the word "goal" or the word "overtime", on the audio channel accompanying the video input to the system. In this way, an advertisement may be scheduled to be incorporated at particular times, such as just after a goal or during overtime. in the present specification, the term "advertisement site" refers to a location into which an advertisement is to be incorporated. If an existing advertisement occupies the advertisement site, the new advertisement replaces the existing advertisement. However, the advertisement site need not be occupied by an existing advertisement. The term "occluded" refers to an advertisement site which is partially or completely concealed by an object, typically a moving object, in front of it. A particular feature of the present invention is that, when it is desired to track an advertisement site within a larger image, the entire image is not tracked, but rather only the advertisement site itself. Another particular feature is that "special" advertisements may be provided, such as moving, blinking or otherwise varying advertisements, video film advertisements, advertisements with changing backgrounds, and advertisements with digital effects. It is appreciated that the particular embodiment described in Appendix A is intended only to provide an extremely detailed disclosure of the present invention and is not intended to be limiting. The applicability of the apparatus and methods described above is not limited to the detection, tracking and replacement or enhancement of advertisements. The disclosed apparatus and methods may, for example, be used to detect and track moving objects of central interest, as shown in Fig. 19, such as focal athletes and such as balls, rackets, clubs and other sports equipment. The images of these moving objects may then be modified by adding a "trail" including an advertisement such as the logo of a manufacturer. It is appreciated that various features of the invention which are, for clarity, described in the contexts of separate embodiments may also be provided in combination in a single embodiment. Conversely, various features of the invention which are, for brevity, described in the context of a single embodiment may also be provided separately or in any suitable subcombination. It will be appreciated by those skilled in the art that, the invention is not limited to what has been shown and described hereihabove. Rather, the scope of the invention is defined solely by the claims which follow: 3 APPENDIX A 3? #include "comp_fnc. " int cdecl compare_short_pnt ( const void *elem1.const void * elem2 ) {int i; double t1,t2; double a; t1 =**(double**)elem1 ;t2=**(double**)elem2; a=t1-t2; i=(a?((a<0)?1:-1):0); return i; } int cdecl compare GOOD_DIR_LINE ( const void * elem1.const void *elem2 ) {int i; double t1,t2; double a; t1 =((GOOD_DIRJJNE*)elem1 )->Qual;t2=((GOOD_DIR_LINE*)elem2)- >Qual; a=t1-t2; i=(a?((a<0)?1 1):0); return i; //===================_===-=-===================== int cdecl compare_arfay_elem ( const void *elem1.const void *eiem2 ) {int i; double a; a=**(double * *)elem1-**(double **)elem2; i=(a?((a<0)?1:-1):0); return i; } //==__:_===========_=__:=========_===================__:========== #ifndef CORJFNC #defιne COR_FNC #include "projctnβ.h" #include "pic_mch8.h" #include "res_mch8.h" typedef struct {double md[3],var[3];} AVERAGE_VEC; AVERAGE_VEC average(PCT tag.double Thr, COLOR_VEC (*p_func-)(COLOR_RGB p1.double Thresh_mdl)); COLOR VEC template_convJ (PCT target.PCT win.double Thr.COfOR_.VEC int_v, COLOR EC (*p_funct)(COLOR_RGB p1.double Thresh_mdl)); COLOR_VEC template abs_diff_1 (PCT target.PCT win.double Thr,COLOR_VEC int_ . COLOR_VEC (*p_funct)(COLOR RGB p1, ouble Thresh_rndl), AVERAGE.VEC t,AVERAGE_VEC w); COLOR VEC Correlation(COLOR_VEC conv,AVERAGE_VEC t,AVERAGE_VEC w. COLOR VEC int v); COLOR VEC Correlation singlej (COLOR_VEC conv.AVERAGE VEC t,AVERAGE_VEC w, COLOR VEC int v); AVERAGE_VEC LineMoments(PCT &T, DIR_LINE Line, short map); double Quality(AVERAGE_VEC * UpLineQuality); #endif -tc #ifndef LIBR #define LIBR #include "projctnδ.h" #include "pic_mch8.h" #include "res mch β .h" / ^include "Iin rn7.h" #define NAMEJ-ENGTH 40 #defιne GRAPHMODE _VRES256COLOR #endif HI typedef struct { int cols, rows; int bpp; } PHDR; ~tλ #ifndef PIC_MCH #defιne PIC ΛCH #include <vmemory.h> #include <graρh.h> #include "projctnδ.h" #defιne MEDIAN_AREA 49 typedef unsigned char byte; typedef struct {short r.g.b;} COLOR_RGB; class PCT {public: short s_rows,s_cols; . unsigned char far * buffer_now ; unsigned char far **pict; //===_================_==============: PCT() {buffer_now=NULL; pict=NULL; s_rows=s_cols=0; } void free_PCT() {int i; if(!pict) return; for(i=0; i<s_rows; i++) free((void far *)pict[i]); buffer_now= N U LL; pict=NULL; } void put_str(short y.unsigned char *B) { if (y <s rows ) {buffer_now=pict[y]; int i; for(i=0;i<3*s_cols;i++) * buffer_now++= * B++; } } void put_pix(short y.short x,COLOR_RGB p) { if((y<s_rows) && (x<s_cols)) buffer_now = pict[y]+3*x; PutNextPix(ρ); } inline COLOR RGB get_next(void) { COLOR_RGB t; t.r=*buffer_now++; t.g=*buffer_ηow++; t.b=*buffer_now++; return t; inline COLOR_RGB get_pixel(short y.short x) { if((y<s_rows) && (x<s_cols)) buffer_now= pict[y]+3*x; return get_next(); } void PutNextPix(COLOR_RGB p); PCT (short n_cols, short n_rows); void load_template(PCT source, SCRJPNT left_up_scr); COLOR_RGB get__median__pixel(short y.short x,short neibour); int load_file_rgb(const char * name); }; void sign_present_RGB(PCT pict_scr,SCR_PNT left_up); PCT sign_storage_rgb(const char *name,struct _videoconfιg vc); COLOR_RGB *make_palette(); short color_num(short r.short g.short b); void write_sign rgb(char *name,PCT pict_ ow); #endif W #ifndef PIC_PRO #defιne PIC_PRO #include <stdlib.h> #include <direct.h> #include <afx.h> #include <ρic_mch7.h> #include Tilemnp.h" #defιne STR_MAX 4 const SCR_PNT z_0(0,0); class PRT:public PCT {public: //information CString PathName; CString FRAME_Number; CString STRING_name; CString SIGN_name; short Pos; // Position in the string long NumberOfChk,MaxNum; double * Charact; //models PRT::~PRT() {this->free_PCT(); Pos=0; if( axNum) delete Charact; Charact=NULL; MaxNum=NumberOfChk=0; } II PRT::PRT() {NumberOfChk=MaxNum=s_cols=s_rows=0; Charact=NULL;pict=NULL; } II PRT::PRT (short n_cols, short n_rows) Charact=NULL; } //=============__:======:====================== int read_proto_SGN(char ext[]=".sgn") { CString new_name(" ',80); PathName=MakeName(PathName); new_name=PathName+ext; char now[80]; IS FILE *datfp; if(!(datfp=fopen((const char*)new name.'V'))) return 1; if(fscanf(datfp,"%*[ Λ \n]s ")==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s M ,now)==EOF)goto ERR; FRAME_Number=now; if (f scanf (datfp,"%s ", now)==EOF)goto ERR;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN_name=now; FRAME_Number.MakeUpper(); STRING_name.MakeUpper(); SIGN_name.MakeUpper(); fclose(datfp); return 0; ERR:fclose (datfp); return 1 ; } //===-==_=_=====__:==:=:_========:=========:========================== int proto_storage_rgb(char *name, struct _videoconfιg vc) {*(PCT *)this=sign_storage_rgb(name,vc); if (!s_cols) return 1; PathName=MakeName(name); if (read_proto_SGN()) {free_PCT(); return 1 ; } return 0; } II int read_proto_DBC(FILE *datfp) { char now[80]; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;PathName=MakeName(now); if(fscanf(datfρ,"%s ",now)==EOF)goto ERR;FRAME_Number=now; if(fscanf(datfρ,"%s ",now)==EOF)goto ERR;STRING_name=now; i7(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN_name=now; if(fscanf(datfp,"%d ",&(this->s_cols))==EOF)goto ERR; FRAME_Number.MakeUpper(); STRINGjiame.MakeUpperO; SIGN_name.MakeUρper(); return 1 ; ERR: return 0; } int alloc_Charact_dbl(long Num) { if(!(Charact=new double[Num])) return 1; MaxNum=Num; NumberOfChk=0; return 0; } // void free_Charact() {delete Charact; Charact=NULL; } // int read_Charact_dbl(FlLE *inp,long Num) {short i; double d; if(MaxNum<(NumberOfChk+Num)) return 1 ; for (i=0;i<Num;i++) {if(fscanf(inp,"%lf H ,&d) ==EOF) return 1; if(fabs(d)<1.0e-4) d=0; Charact[NumberOfChk]=d; NumberOfChk++; } return 0; } // double CorrValue(short WNum.short Pnum) {return (*(Charact+(long)WNum*s cols+Pnum)); } //======RETURN NUMBER OF STRIPS int read_target_SGN(SCR_PNT vrt[][4],char ext[]=".sgs") {int n=0,j,FLG,s; CString new_name(' ',80); PathName=MakeName(PathName); new_name=PathName+ext; char now[80]; FILE *datfp; if(!(datfp=fopen((const char * )new name,"r"))) return 1; if(fscanf(datfp,"% * [ Λ \n]s ")= " ^EOF)goto OUT; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; if(fscanf(datfp,"%s ",now)==EOF)goto OUT;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; SIGN_name=now; if((s=PathName.ReverseFind('\V))<0) s=PathName.ReverseFind(':'); FRAME_Number= PathName.Right(PathName.GetLengthO-s); HI STRING_name.MakeUpper(); SIGN_name.MakeUpper(); do{ for(j=0;j<4;j++) if((FLG=fscanf(datfp, ,, %d %d ",&(vrt[nlϋ].c),&(vrt[n]0].r)))==EOF) goto OUT; n++; } while(n<STR_MAX-1); OUT:fclose (datfp); return n; } II }; /=====:==:==_=__:__:======:======__:==__:===_=-=======-_:= #define UnKnown -1 //=: S ==_ = __._=====___:_:====__=__==__∞ typedef struct { short n; // voiting numbers short pos; // position in string double value; //value } RSLT_old; II . void HistCollect(short NOfWin.short Stshort Fin.PRT &Db); RSLT_old LineEstimation (short TagSize, PRT &Db,short NOfWin, short WSize.double Thr); int Linelnf(const PRT &P, PRT T, short rw, short Xpos.struct _videoconfig vc); double Linlnter( PRT &P,short WNum.short WSize .double Pt); void HistThresh(short * H,short * BotThr,short *TopThr,short num); #endif W #ifndef PROJCTN #defιne PROJCTN #include <math.h> #include <graph.h> typedef struct { double x, y, z; } PNT; class SCR_PNT {public: short c, r; SCR_PNT(){c=0;r=0;} SCR PNT(short x,short y){c=x;r=y;} } ; ~ //PT -> SCR_PNT conversion // #defιne PT_SCR( p.scr) (scr).c=(short)(p).u;(scr).r=(short)(p).v; // SCR_PNT -> PT converson #defιne INT_PT(scr,dbl) (dbl).u=(double)((scr).c);\ (dbl).v=(double)((scr).r); class PT {public: double u, v; PT(double x, double y){u=x; v=y;} PT(SCR_PNT p1 ){u=(double)p c;v=(double)p1.r,} PT (){u=0;v=0;} } ; class LINE_PROJECTION; class DIR_LINE { friend class LINE_PROJECTION; private: double a.b.c; // a * u+b*v+c=0 PT st_pnt, end_pnt; public: DIR_LINE (PT p1, PT p2) {st_pnt=p1; end_pnt=p2; #ifdef DEBUG _moveto( (short) st_pnt.u,(short) st_pnt.v ); _lineto( (short) end_pnt.u,(short) end_pnt.v ); #endif a=p2.v-p1.v; b=p1.u-p2.u; c=p1.v * p2.u-p1.u*p2.v; // a*x+b * y+c=0 } //- DIR_LINE (SCR_PNT p1, SCR.PNT p2) {st_pnt=PT::PT(p1); end_pnt=PT::PT(p2); #ifdef DEBUG _moveto( (short) st_pnt.u, (short) st_pnt.v ); Jineto( (short) end_pnt.u,(short) end_pnt.v ); #endif a=end_pnt.v-st_pnt.v; b=st_pnt.u-end_pnt.u; c=stjDnt.v*end_ρnt.u-stjDnt.u*end Dnt.v; // a*x+b*y+c=0 } DIR_LINE () {st_pnt.u=st_pnt.v= end_pnt.u=end_pnt.v=a=b=c=0; P p) t.u=st_pnt.u+p*(end_pnt.u-st_pnt.u); t.v=st_pnt.v+p*(end_pnt.v-st_pnt.v); return t; } double U_for_V(double v) {return(a?(-c-b*v)/a:0);} double V_for_U(double u) {retum(b?(-c-a*u)/b:0);} double a_forJine(){return a;} double b_for_line(){return b;} double c_forJine(){return c;} double RATIO_for_PT(PT p) //relative point position at line { double dx.dy.dro; dx=end jDnt. u-st_pnt. u; dy=end_pnt.v-st_pnt.v; if(fabs (dx)>fabs(dy)) {if(!dx) return 0; dro= (p.u-st_pnt.u)/dx; } else { if(!dy) return 0; dro= (p.v-st_pnt.v)/dy; } return dro; } int Left_Right(int col, int row) // +1 if point to the left hand from start to end // 0 otherwise { return(((a * col+b * row+c)>=0)?0: 1 ); } PT Start_ρ(){return st_pnt;} PT End_p(){return end_pnt;} friend int U_dist(DIR_LINE I); friend PT cross line(DIR_LINE Linel, DIR LINE Line2); friend int INside(DIR_LINE I1.DIR_.L1NE I2,DIR_LINE I3,DIR_LINE I4,int col, int row); }; class LINE_PROJECTION { private: double proj_prm; // public: DIR_LINE Rl, Prj; LINE_PROJECTION(){ DIR_LINE I1; RN1; Prj=l1; proj_prm=0; } LINE_PROJECTION (DIRJ NE 11, PT p, DIR_LINE pr, PT p_pr); double Ro_for_P(double P) {return ( (P*(1+ρroj_prπι))/(1+P * pr°L_ rπ.)); } double P_for_Ro(double Ro) {return ( Ro/(1+(1-Ro)*proj_prm)); } friend DIR LINE Line for_PT_pr(LINE PROJECTION linel , PT pr1 , LINE_PROJECTION Iine2, PT pr2); friend DIR_LINE Line_for_PT_rl(LINE_PROJECTION linel, PT p1, LINE_PROJECTION Iine2, PT p2); }; //==_===-==:=_=__:===__:===__:====_=__:=======_=====:==== class GOOD_DIR_LINE:public DIR_LINE {public : double Qual; GOOD_DIR_LINE(){Qual=0;} GOOD_DIR_LINE(SCR_PNT St,SCR_PNT End) {Qual=0; *(DIR_LINE *)this=DIR_LINE::DIR LINE(St.End); } // void OnDraw(short incr) // { PT st=Start_p(), stp=End_p(); // _moveto( (short) st.u.(short) (st.v+incr) ); // _lineto( (short) stp.u,(short) (stp.v+incr) ); // } }; typedef struct{ LINE_PROJECTION L_left,L_mid,L_right; DIR LINE 101.112.123.130; DIR -INE I01_pr, I12_pr, I23_pr. I30_pπ RECT_RESOLVED; #endif #ifndef RES_MCH #defιne RES_MCH #include <graph.h> #include "projctnδ.h" #include "pic_mch8.h" #defιne NTSC 0 #defιne HS1 1 #define New_plan 2 #define RGB 3 #define LUMIN_THR 4 #define IHS 5 typedef struct {double c[3]; } COLOR_VEC; void GRAPH_OUT(int ex=0); int GRAPHICS_START(struct _videoconfιg *vc,short GR_mode); void match_ ertex(SCR_PNT * v); int cdecl c_comp( const void *elem1 , const void *elem2); short interpol(short * s.double x,double y); COLOR_RGB INTER_pix_color_rgb(PCT p1, PT PT_ ow); COLOR_RGB INTER_pix_color_rgb_median(PCT pϊ " , PT PT_now); const COLOR_VEC NORM_RGB={256,1,1}; const COLOR_VEC NORM_simple={256,256,256}; COLOR_VEC ( * PointColorFunct(short M))(COLOR_RGB p1, double Thresh_mdl); COLOR_VEC color_space_NTSC(COLOR_RGB p1.double Thresh_mdl); COLOR_VEC color space RGB(COLOR_RGB p1, double Thresh_mdl); COLOR_VEC color~space~NEW(COLOR_RGB p1, double Thresh_mdl); COLOR_VEC color_space_RGB_simple(COLOR_RGB p1 , double Threshjndl); COLOR_VEC color_space_LUMIN_THR(COLOR_RGB p1, double Thresh_mdl); COLOR_VEC color_space_IHS(COLOR_RGB p1, double Thresh_mdl); #endif #ifndef VICAL8 #defιne VICAL8 #include <vmemory.h> typedef unsigned char byte; __ __ .. ■ unsigned char _far - virtalloc(short xdim.short yd i m); #endif S #include "comρ_fnc.h" int cdecl compare_short_pnt ( const void *elem1, const void * elem2 ) {int i; double t1,t2; double a; t1 =**(double**)elem1 ;t2=**(double * *)elem2; a=t1-t2; i=(a?((a<0)?1:-1):0); return i; } * int cdecl compare_GOOD_DIR_LINE ( const void * elem1.const void *elem2 ) {int i; double t1,t2; double a; t1 =((GOOD_DIR_LINE*)elem1 )->Qual;t2=((GOOD_DIR_LINE * )elem2)- >Qual; a=t1-t2; i=(a?((a<0)?1 :-1):0); return i; } //============================__======∞ //==_====___=====_=_====_=___==__==__==__======_==_==_==== int ^cdecl compare_array_elem ( const void * elem1, const void *elem2 ) {int i; double a; a=**(double * *)elem1-**(double **)elem2; i=(a?((a<0)?1:-1):0); return i; } //= = =======__===================__=^^ εε #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <float.h> #include <graph.h> #include "cor ncδ.h" /==_======_=_======_==-_-_====-===-==---=-==-=======-======:-==== AVERAGE_VEC average(PCT tag.double Thr, COLOR_VEC (*p_funct)(COLOR_RGB p1.double Thresh_mdl)) {short r_t,c_t,n=0,i; AVERAGE_VEC z {0,0,0},{0,0,0}}; COLOR_VEC t_p; for(r_t=0;r_t<tag.s_rows;r_t++) f or(c_t=0; c_t<tag. s_cols; c_t++) {n++; t_p=p_funct(tag.getj3ixel(r_t,c_t),Thr); for(i=0;i<3;i++) { z.md[i]+=t_p.c[i]; z.var[i]+=t_p.c[i]*t_p.c[i]; } } double rr.nrev; nrev=n?1.0/n:0; for(i=0;i<3;i++) {rr=(z.md[i]*=nrev); z.var[i]=z.var[i]*nrev; } return z; } //===================__==:__==========_^ COLOR_VEC template_conv_1 (PCT target.PCT win.double Thr,COLOR_VEC int_v, COLOR_VEC ( * p_funct)(COLOR_RGB p1, double Thresh_mdl)) {short i,r,c,n; COLOR_VEC w_p,t_p; COLOR_VEC res={0,0,0}; for(n=r=0; (r<target.s_rows)||(r<win.s_rows);r++) for(c=0; (c<target.s_cols)||(c<win.s_cols);c++) {n++; w_p=p_funct(win.get_pixel(r,c),Thr); t_ρ=p_funct(target.get_pixel(r,c),Thr); for(i=0;i<3;i++) 6 if(int_v.c[i]) res.c[i]+=w_p.c[i]*t_p.c[i]; } double nrev; nrev=n?1.0/n:0; for(i=0;i<3;i++) res.c[i]=res.c[i]*nrev; return res; } COLOR VEC template_abs diff 1 (PCT target.PCT win.double Thr.COfOR VEC int v, COLOR_VEC (*p_funct)(COLOR RGB p1.double Thresh mdl), AVERAGE_VEC t,AVERAGE_VEC w) {short i.r.c.n; COLOR VEC w_p,t_p; COLOR_VEC res={0,0,0},nor={0,0,0}; for(n=r=0; (r<target.s_rows)||(r<win.s_rows);r++) for(c=0; (c<target.s_cols)j|(c<win.s_cols);c++) {n++; w_p=p_funct(win.get_pixel(r,c),Thr); t_p=p_funct(target.get_pixel(r,c),Thr); for(i=0;i<3;i++) if(int_v.c[i]) {res.c[i]+=fabs(w_p.c[i]-t_p.c[i]-w.md[i]+t.md[i]); nor.c[i]+= max (fabs(w_p.c[i]-w.md[i]),fabs(t_p.c[i]-t.md[i])); // nor.c[i]+=2 * fabs(w_p.c[i]-w.md[i]); } } for(i=0;i<3;i++) if(int_v.c[i]&& nor.c[i]) res.c[i]=1 -res.c[i]/nor.c[i]; return res; } COLOR_VEC Correlation(COLOR_VEC conv,AVERAGE_VEC t,AVERAGE_VEC w, COLOR_VEC int_v) {COLOR_VEC out; int i; double p,g; for(i=0;i<3;i++) if(int_v.c[i]) 5 ~ {p=(conv.c[i]-t. md[i]*w. md[i]); g=(t.var[i]-t.md[i]*t.md[i])*(w.var[i]-w.md[i]*w.md[i]); out.c[i]=g?p * p/g:0; out.c[i]=(p>0)?out.c[i]:-out.c[i]; } else out.c[i]=0.0; return out; } //==_===____===._:____==-_===r_^ / • COLOR VEC Correlation single l (COLOR_VEC conv,AVERAGE_VEC t,AVERAGE_VEC w. COLOR_VEC int v) {COLOR_VEC out; int i; double sngl_conv=0; double sngl_var=0; for(i=0;i<3;i++) if(int v.c[i]) { sngl_conv+=conv.c[i]; sngl_var+=t.var[i]+w.var[i]; } out.c[0]=out.c[1]=out.c[2]=sngl_conv/sngl_var; return out; AVERAGE_VEC LineMoments(PCT &T, DIR_LINE Line.short map) {COLOR RGB col; COLOR_VEC vc; AVERAGE_VEC out={{0.0,0.0,0.0}.{0.0,0.0,0.0}}; PT now; short length=U_dist( Line); double d; short j,i.k,ST_X ! END_X,now_X; double relen,delta_V; PT st, stop; if(length<0) {st=ϋne.End_p(); stop=ϋne.Start_p(); length=fabs(length); } else {st=ϋne.Start_p(); stop=Line.End_p(); } relen= length?1.0/length:0; ST_X=(short)st.u; END_X=(short)stop.u; if(delta_V=(stop.v-st.v) * relen) fo " r(d=st.v+0.5,now_X=ST X;now_X<END_X;now X++,d+=delta V) { // now.u=ST_X;now.v=d; // col=INTER_pix_color_rgb(T, now); col=T.get_pixel((short)d,now_X); switch (map) {caseNTSC:; caseNew_plan:; caseHSI:; caseIHS:{ vc= PointColorFunct(map)(col.O); for(k=0;k<3;k++) out.md[k]+=vc.c[k]; break; } caseRGB: { out.md[0]+=col.r;//out.var[0]+=col.r*col.r; out.md[1 ]+=col.g;//out.var[1 ]+=col.g*col.g; out.md[2]+=col.b;//out.var[2]+=col.b * col.b; break; } case LUMIN_THR:{ out.md[0]+=col.r+col.g+col.b; break; } }; }; for(j=0;j<3;j++) { out.mdjj]*=relen; // out.var[j]/=length; } return out; } double Quality(AVERAGE_VEC * UpϋneQuality) {short i,j; double out,out_even=0,out_odd=0,out2_even,out2_odd,sum=0; forϋ=0;j<3;j++) { sum+=(UpLineQuality+0)->md ]+(UpϋneQuality+1)->md[j]+ 5 < l (UpLineQuality+2)->md[j]+(UpLineQuality+3)->mdϋ]; out2_even=(UpLineQuality+0)->mdO]+(UpLineQuality+1)->mdD]- (UpLineQuality+2)->md[j]-(UpLineQuality+3)->mdϋ]; out2_even * =out2_even; out2_odd=(UρLineQuality+0)->mdD]-(UpLineQuality+1)->mdϋ]- " (UρLlneQuality+2)->mdD]+(UρLineQuality+3)->mdO]; out2_odd*=out2_odd; out_even+=out2_even; out_odd+=out2_odd; } out=(out_even+out_odd)*0.001 ; return out; } #include<stdlib.h> #include<stdio.h> #include<graph.h> #include<math.h> #include <io.h> #include<fcntl.h> #include <string.h> #include <float.h> #include <malloc.h> #include "phdr.h" #iήclude "vicalδ.h" #include "pic_mch8.h" int cols, rows; PHDR inhdr; //===_==__:====-===============:====-== //=__=_.====================_=-_======= void PCT::PutNextPix(COLOR_RGB p) { *buffer_now++ = (unsigned char)p.r; *buffer_now++ = (unsigned char)p.g; *buffer now ++ = (unsigned char)p.b; //= int cdecl comparejum ( const void * elem1, const void *elem2 ) {int i; COLOR_RGB t1,t2; double a; t1 = ** (COLOR_RGB ** )elem1 ;t2= ** (COLOR_RGB ** )elem2; a=(t1.r+t1.g+t1.b-t2.r-t2.g-t2.b); i=(a?((a<0)?1:-1):0); return i; } /=_=====__=_=============_=_====-_====__===:====_:=======_.==: /_===__======-_====__==:===:=__:=__:_==:============__:==__:====_====: COLOR_RGB PCT::get_median_pixel(short y.short x.short neibour) {COLOR_RGB t={0,0,0}, s[MEDIAN_AREA],*lum_order[MEDIAN_AREA]; short n,i,j,xnow,ynow; int x3=3 * x; unsigned char far *buffer1 ;, for(n=0,i=-neibour;i<=neibour;i++) for(j=-neibour;j<=neibour;j++) if(((ynow=y+i)<s_rows) && ((xnow=x+j)<s cols)) { bufferl = (unsigned char far * ) pict[ynow]; t.r=*(buffer1 +xnow*3+0); t.g=*(buffer1 +xnow * 3+1 ); t.b=*(buffer1+xnow*3+2); s[n]=t; r *(lum_order+n)=s+n; n++; } qsort((void*)lum_order,n,sizeof(COLOR_RGB*),compareJum ); t=*lum_order[(n+1 )»1 ]; return t; }_ PCT::PCT( short n cols, short n rows) { pict= (unsigned char far * *)virtalloc(3*n_cols,n_rows); if (Ipict) {fprintf(stderr,"No memory for picture "); s_cols=0; s_rows=0;- return; } buffer_now=pict[0]; s_cols=n_cols; s_rows=n_rows; } //======_====-=====:========-_:=_=-===== void PCT::load_tempiate(PCT source, SCR_PNT left_up_scr) { short r_now, c_now; COLOR_RGB color_p; unsigned char *BUF,*B; BUF=(unsigned char *) malloc((size_t) (sizeof(unsigned char)*3*s_cols)); if(!BUF) {fprintf(stderr," BUF ");exit(-1);} for (r_now=0; r_now<s_rows;r_now++) { for (B=BUF.c_now=0;c_now<s_cols; c_now++) { color_p= source.get_pixel(r_now+left_up_scr.r,c_now+left_up_scr.c); * B++=color_p.r; * B++=color_p.g; * B++=color_p.b; } b-~ put_str(r_now, BUF); } free((void*)BUF); } //=" int PCT::load_fιle_rgb(const char *name) { int er_r; short bytes; int y, infd; short ysize, xsize; char name of file[18]; FILE *datfp; " strcat(strcpy(name_of_file,name),".rgb"); datfp=fopen(name_of_file,"rb"); infd= _fileno( datfp ); if(infd <= 0) { printfC'bad name 1"); return(1 ); } er_r=_read(infd, &inhdr, sizeof(PHDR)); xsize=cols = inhdr.cols; ysize=rows = inhdr.rows; if(ysize > s_rows ) ysize =s_rows; if(xsize > s_cols) xsize = s_cols; s_cols= xsize; s_rows=ysize; bytes =3 * xsize; byte Buf[2040]; for(y = 0; y < ysize; y++) { read(infd, Buf, 3 * cols); put_str(y, (unsigned char*)Buf); } fclose(datfp); return 0; } //= PCT sign_storage_rgb(const char * name, struct _videoconfig vc) { int er_r; fe3 PCT pict_now; char name_of_file[40]; FILE * datfp; strcat(strcpy(name_of_fιle, name) , ". rgb"); int infd; short ysize, xsize; datfp=fopen(name_pf_file,"rb"); infd= fιleno( datfp ); if(infd <= 0) { printf("bad name 1"); return(pict_now); } er_r=_read(infd, &inhdr, sizeof(PHDR)); if(er_r<0) { printffbad name 1"); return(pict now); } fclose(datfp); xsize=cols = inhdr.cols; ysize=rows = inhdr.rows; if (ysize > vc.numypixels ) ysize = vc.numypixels ; if (xsize > vc.numxpixels) xsize = vc.numxpixels; pict_now=PCT::PCT(xsize,ysize); if(pict_now.s_cols) pict_now. load_file_rgb(name); retum(pict_now); } /*=========================:__========^ void sign_present_RGB(PCT pict_scr,SCR_PNT leftjjp) {short x,y,xsize,ysize; COLOR_RGB t; xsize= pict_scr.s_cols; ysize= pict_scr.s_rows; short c; for(y = 0; y < ysize; y++) {pict_scr.buffer_ ow=pict_scr.pict[y]; for(x = 0; x < xsize; x++) { t=pict_scr.get_next(); _setcolor(color_num (t.r»2,t.g»2,t.b»2)); _setpixel(x+left_up.c,y+left_up.r); } } } //=========:-====-_:=:==:=-=================-_: const int stepr=9, stepg=9, stepb=21 ; COLOR_RGB * make_palette() {COLOR_RGB *plt=NULL; long now,Lut[256]; long dr.dg.db; short i,j,k,num; for(i=0,db=0;i<4;i++,db+=stepb) for(j=0,dg=0;j<8;j++,dg+=stepg) for(k=0,dr=0;k<8;k++,dr+=stepr) { now=(db«16)l(dg«8)|dr; num=(i«6)|(j«3)|k; Lut[num]=now, } _remapallpalette((long far *)Lut); return pit; } //==_ = ========_==== S :===:==:=======_=========: short color_num(short r.short g.short b) {short num.ij.k; i=(b+(stepb»1 ))/stepb; * j=(g+(stepg»1 ))/stepg; k=(r+(stepr»1 ))/stepr; num=(i«6)|(j«3)|k; return num; } //=======_======_==============_==__:=_====:=== void write_sign_rgb(char *name,PCT pictjiow) { int er_r;; char name_of_fιle[80]; strcat(strcpy(name_of_file,name),".rgb"); FILE *datfp; int y, infd; datfp=fopen(name_of_file,"wb"); infd= _fileno( datfp ); if(infd <= 0) ρrintf("bad name 1"); inhdr.cols=pict_now.s_cols; inhdr.rows=pict_now.s_rows; inhdr.bpp=3; er_r=_write(infd, (void *)(&inhdr), sizeof(PHDR)); for(y = 0; y < pict_now.s_rows; y++) C 65 #ifdef VIRTUAL void far *buffer1 ; if ( (bufferl = (void__far *)_vload( pict_now.pict[y],_VM_CLEAN )) == NULL ) {_ heapterm();exit( -1 ); } #else void *buffer1; bufferl = (void *) pict_now.pict[y]; #endif er_r=_write(infd, bufferl, sizeof(char) * pict_now.s cols * 3); } fclose(datfp); strcat(strcpy(name_of_fιle, name) ,". sgn"); datfp=fopen(name_of_fιle,"w"); fprintf(datfp,"%s \n θ " b\rV',name); fprintf(datfp,"%d 0\n",ρict_now.s_cols-1 ); fprintf(datfp,"%d %d \n",pict_now.s_cois-1 ,pict_now.s_rows-1 ); fprintfjdatfp," 0 %d\n",ρict_now.s_rows-1); fclose(datfp); } //=======»=========_:_:_:=_:__===_:=_:=====_:_:==_:_:=====_:_:===»_:=_:== #include<stdlib.h> #include<stdio.h> #include<graph.h> #include<math.h> #include <io.h> #include<fcntl.h> #include <string.h> #include <float.h> /^include <malloc.h> //#include "phdr.h" //#include "vicalδ.h" #include "picture.h" //int cols, rows; //PHDR inhdr; COLOR RGB PCT::get_median_pixel(short y.short x,short neibour) {COLOR_RGB t={0,0,0}, s[MEDIAN_AREA],*lum_order[MEDIAN_AREA]; short n.i.j.xnow.ynow; int x3=3*x; unsigned char far *buffer1 ; for(n=0,i=-neibour;i<=neibour;i++) for(j=-neibour;j<=neibour;j++) if(((ynow=y+i)<s_rows) && ((xnow=x+j)<s_cols)) { bufferl = (unsigned char far *) pict[ynow]; t.r= * (buffer1 +xnow*3+0); t.g=*(buffer1 +xnow*3+1 ); t.b=*(buffer1 +xnow*3+2); s[n]=t; *(lum_order+n)=s+n; n++; } qsort((void * )lum_order,n,sizeof(COLOR_RGB * ),compare_lum ); t=*lum_order[(n+1 )»1 ]; return t; } //===:====__.==___====__::_:=====-_:===^^ PCT::PCT( short n_cols, short n_rows) { pict= (unsigned char ^far ** )virtalloc(3 * n_cols,n_rows); if (Ipict) {fprintf(stderr,"No memory for picture "); s_cols=0; s_rows=0; -TΛ return; } buffer_now=pict[0]; s_cols=n_cols; s_rows=n rows; } void PCT::load emplate(PCT source,SCR_PNT left_up_scr) { short r_now, c_now; COLOR_RGB~color_p; unsigned char *BUF, * B; BUF=(unsigned char * ) malloc((size_t) (sizeof(unsigned char)*3*s cols)); if(!BUF) {fprintf(stderr," BUF ");exit(-1 ) • } for (r_now-0; r_now<s__rows;r_now++) { for (B=BUF,c_now=0;c now<s_cols; c_now++) { color_p= source.get_pixel(r_now+left_up_scr.r,c_now+left_up_scr.c); *B++=color_p.r; *B++=color_p.g; * B++=color_p.b; } put* str(r_now,BUF); } free((void * )BUF); } //_=_==_=============__:========_ int PCT::load_file_jgb(const char *name) { int er jshort bytes; int y, infd; short ysize, xsize; char name_pf_file[18]; FILE *datfp; strcat(strcpy(name_of_file,name),".rgb"); datfp=fopen(name_of_file,"rb"); infd= _fιleno( datfp ); if(infd <= 0) { printf("bad name 1"); return(1); } er_r=_read(infd, &inhdr, sizeof(PHDR)); xsize=cols = inhdr.cols; ' ysize=rows = inhdr.rows; 66 if(ysize > s_rows ) ysize =s_rows; if(xsize > s_cols) xsize = s_cols; s_cols= xsize; s_rows=ysize; bytes =3 * xsize; byte Buf{2040]; for(y = 0; y < ysize; y++) { read(infd, Buf, 3*cols); put str(y, (unsigned char * )Buf); } " fclose(datfp); return 0; } //= PCT sign_storage_rgb(const char *name, struct _ ideoconfig vc) { inter ; PCT pictjiow; char name_of file[40]; FILE *datfp; strcat(strcpy(name_of_file,name),".rgb"); int infd; short ysize, xsize; datfp=fopen(name_of_fιle,"rb"); infd= fιleno( datfp ); if(Iήfd <= 0) { printf("bad name 1"); retum(pict_now); } er_r=_read(infd, &inhdr, sizeof(PHDR)); if(er_r<0) { printf("bad name 1"); return(pict_now); } fclose(datfp); xsize=cols = inhdr.cols; ysize=rows = inhdr.rows; if (ysize > vc.numypixels ) ysize = vc.numypixels ; if(xsize > vc.numxpixels) xsize = vc.numxpixels; pict_now=PCT::PCT(xsize,ysize); if(pict_now.s_cols) pict_now.load_file_rgb(name); return(pict now); } void sign_present_RGB(PCT pict_scr,SCR_PNT left_up) {short x.y.xsize.ysize; COLOR_RGB t; xsize= pict_scr.s_cols; ysize= pict_scr.s_rows; short c; for(y = 0; y < ysize; y++) {pict_scr. buff er_now=pict_scr. pict[y]; for(x = 0; x < xsize; x++) { t=pict_scr.get_next(); _setcolor(color_num (t.r»2,t.g»2,t.b»2)); setpixel(x+left up.c,y+left_up.r); } ~ } } const int stepr=9, stepg=9, stepb=21 ; COLOR RGB *make_palette() {COLOR_RGB *plt=NULL; long now,Lut[256]; long dr.dg.db; short ij.k.num; for(i=0,db=0;i<4;i++,db+=stepb) for(j=0,dg=0;j<8;j++,dg+=stepg) for(k=0,dr=0;k<8;k++,dr+=stepr) { now=(db«16)|(dg«8)|dr; num=(i«6)|(j«3)|k; Lut[num]=now; } _remapallpalette((long ^far *)Lut); return pit; } //_====_=_=====================_====_====:====:=== short color_num(short r.short g.short b) {short num.i.j.k; i=(b+(stepb»1 ))/stepb; no j=(g+(steρg»1))/steρg; k=(r+(steρr»1 ))/stepr, num=(i«6)|(j«3)|k; return num; } // ==:= =:=____====:===:===========^^ void write_sign_rgb(char *name,PCT pict_now) { int er_π; char name_of_file[80]; strcat(strcpy(name_of file,name),".rgb"); FILE *datfp; int y, infd; datfp=fopen(name_of_file,"wb"); infd= fileno( datfp ); if(irιfd <= 0) printf("bad name 1"); inhdr.cols=pict_now.s_cols; inhdr. rows=pict_now. s_rows; inhdr.bpp=3; er_r=_write(infd, (void *)(&inhdr), sizeof(PHDR)); for(y = 0; y < pict now.s rows; y++) { #ifdef VIRTUAL void far *buffer1; if ( (bufferl = (void __far * )_vload( pict_now.pict[y],_VM CLEAN )) == NULL ) {_vheapterm();exit( -1 ); } #else void * buffer1; bufferl = (void * ) pict_now.pict[y]; #endif er_r= write(infd, bufferl, sizeof(char)*pict_now.s_cols*3); } fclose(datfp); strcat(strcpy(name_of_fiie,name),".sgn"); datfp=fopen(name_of_fιle,"w"); fprintf(datfp,"%s \n 00\n",name); fprintf(datfp,"%d 0\n",ρict_now.s_cols-1 ); fprintf(datfp,"%d %d \n",pict__now.s_cols-1 ,pict_now.s_rows-1 ); fprintf(datfp," 0 %d\n",pict_now.s_rows-1); fclose(datfp); } /========-_===__======================-====-==-========== ι #include <graph.h> #include <stdlib.h> #include <iostream.h> #include "projctnδ.h" // For Constructor Calculate ratio of Lengthes. // FOR CONSTRUCTOR Fill Members //8888888888β LINE_RROJECTION :: LINE PROJECTION (DIRJ NE 11. PT p, DIR .INE pr, PT p_pr) { double P, Ro; RN1; Prj=pr; P = l1.RATIO_for_PT( p); Ro= pr.RATld_for_PT( p_pr); if (P && (1-Ro)) {proj_prm=(Ro-P)/(P*(1-Ro));return;}; cout « "LINE UNRESOLVABLEXn"; } PT cross_line(DIR_LINE Linel, DIR LINE Line2) {PT out; double det; if(det=Line1.a*Line2.b-Line2.a*Line1.b) {out.u=(Line1.b*Line2.c-Line1.c * ϋne2.b)/det; out.v=(Line1.c * Line2.a-ϋne2.c*Line1.a)/det; } else out.u=out.v=0; #ifdef DEBUG _setcolor(0); _ellipse(_GFILLINTERIOR, (short) (out.u-1), (short) (out.v-1), (short) (out.u+1),(short) (out.v+1)); #endif return out; } // Bield real space line connecting points X1 and X2 /// X1 belongs to linel, X2 to Iine2: // PT pr1 - projection X1 // PT pr2 - projection X2 // LINE_PROJECTION linel, Iine2 DIR LINE Line_for_PT_pr(LINE_PROJECTION linel, PT prI, LINE_PROJECTION Iine2, PT pr2) { double P.Ro; PT p1, p2; Ro=line1.Prj.RATIO_for_PT( pr1 ); //relative point position at line P=line1.P_for_Ro( Ro); p1=line1.RI.PT_for_P(P); Ro=line2.Prj.RATIO_for_PT( pr2); //relative point position at line P=line2.P_for Ro( Ro); p2=line2.RI.PT_for_P(P); DIRJ NE In(p1 ,p2); return(ln); } // Bield projection line connecting points p1 and p2 /// p1 belongs to linel , p2 to Iine2: // PT p1 - projection X1 // PT p2 - projection X2 // LINE_PROJECTION linel , Iine2 DIR LINE Line_for_PT_rl(LINE PROJECTION linel, PT p1, LINE_PROJECTION Iine2, PT p2) {double P.Ro; PT plpr, p2pr; P=line1.RI.RATIO_for_PT( p1 ); //relative point position at line Ro=line1.Ro_for_P( P); p1pr=line1.Prj.PT_for_P(Ro); P=line2.RI.RATIO_for_PT( p2); //relative point position at line Ro=line2.Ro_for_P( P) p2pr=Iine2.Prj.PT_for_P(Ro); DIRJJNE In(p1pr,p2pr); return(ln); } //====:===_==_======__:==__:===__:=-========__========____=== // =1 if point P in quagrangle int INside(DIR_LINE 11. DIRJJNE I2.DIRJJNE I3.DIRJJNE I4,int col.int row) {return(l1.Left_Right(col,row)&&l2.Left_Right(col,row)&& l3.Left_Right(col,row)&&l4.Left_Right(col,row)); } /==:===__==:====:__:=======-====-=====__==__=-=======_==_==== int U_dist(DIR_LINE I) {return (l.end_pnt.u- l.st_pnt.u) ; } //===========_==--=--==_=================================: #include <stdlib.h> #include <vmemory.h> #include "res_mch8.h" #defιne AVERAGE #defιne SMOOSEJNT 1 extern double GAMMA; COLOR_VEC (*PointColorFunct(short M))(COLOR_RGB p1, double Thresh_mdl) { switch ( M) {case NTS C : retum(color_space_NTSC ); case New_plan:return(color_space_NEW); case HSI:return(color_space_RGB); case RGB:retum(color_space_RGB_simple); case LUMIN_THR:return(color_space_LUMIN_THR); case IHS:return(color spaceJHS); }; return NULL; } //======_====_==_=_.================== void GRAPH_OUT(int ex)- { _displaycursor( _GCURSORON ); _setvideomode( _DEFAULTMODE ); if (ex) exit (ex); } //============================-==========^^ int GRAPHICS START(struct _videoconfig *p_vc,short GR_mode) { _displaycursor( _GCURSOROFF ); _setvideomode( GR_mode ); if(_grstatus( ) <0) retum(1); _getvideoconfig( p_vc ); make_palette(); return 0; } // sorting vertexes int cdecl c_comp( const void * elem1 , const void *elem2) { if (((SCR_PNT*)elem1)->c >((SCR_PNT *) elem2)->c) return 1 ; else if(((SCR_PNT *) elem1)->c < ((SCR_PNT * )elem2)->c) return -1 ; else return 0; } II void match_vertex(SCR_PNT *v) { SCR_PNT vrt[4]; if(vrt[2].r < vrt[3].r) {V=vrt[2]; * (v+1)=vrt[3];} else inline short interpol(short * s.double x,double y) {double r=s[0]+x*y*(s[0]-s[1 ]+s[2]-s[3])+x * (s[1 ]-s[0])+y*(s[3]-s[0]); return((short)r); } //=======:___===:===:===_=====_=_=∞ // ONLY FOR INTER_pix_color_rgb // and INTER_pix color_rgb_median /===========_=—=_=_===_========_=____:=:===__=_=====__==_==== inline COLOR_RGB BEJinear(COLOR_RGB *p,double x ract.double y ract) // loop over coolr {short s[4]; COLOR RGB out_col; s[0]=p[0].r; s[1]=p[1].r; s[2]=p[2].r; s[3]=p[3].r; out_col.r=(short) interpol(s,xJract,yJract); s[0]=p[0].g; s[1]=p[1].g; s[2]=p[2].g; s[3]=p[3].g; out_col.g=(short) interpol(s,xJract,yJract); s[0]=p[0].b; s[1]=p[1].b; s[2]=p[2].b; s[3]=p[3].b; ns out_col.b=(short) interpol(s,xJract,yJract); return out_col; COLOR RGB INTER_pix color_rgb(PCT p1, PT PT iow) { int colO=(int)PT_now.u, r row0=(int)PT_now.v; double x fract=PT_now.u-colO, yJract=PT_now.v-rowO; COLOR_RGB p[4]; p[0]=p1.get_pixel(rowO,colO); p[1]=ρlget_next(); p[3]=p1.get_pixel(row0+1 ,col0); p[2]=p get_next(); return ( BE linear( p, x ract, y fract)); } COLOR_RGB INTER_pix color rgb median(PCT p1, PT PT_now) { int col0=(int)PT_now.u, row0=(int)PT_now.v; double x fract=PT now.u-colO, yJract=PT now.v-rowO; COLORJRGB p[4]~ p[0]=p1.get_median_pixel(row0,col0,SMOOSEJNT); p[1 ]=p1.get_median_pixel(row0,col0+1.SMOOSEJNT); p[2]=p1.get_median_pixel(row0+1 ,col0+1.SMOOSEJNT); p[3]=p1.get_median_pixel(row0+1.colO.SMOOSEJNT); return ( BEJinear( p, x fract, y ract)); } //=:==_ = =__======___:_ =__=__:__==:=__= ∞ #defιne NTSCr(c) ((c).r*0.6-(c).g * 0.28-(c).b*0.32) #define NTSCg(c) (0.21 * (c).r-0_52*(c).g+0_31*(c).b) #define NTSCw(c) (0.3 * (c).r+0.59*(c).g+0.11*(c).b) COLOR_VEC color_space NTSC(COLOR_RGB p1 , double Thresh mdl) {COLOR. VΕC out={0,0,0}; if((out.c[0]= NTSCw(p1 ))>Thresh_mdl) {out.c[1]= NTSCr(p1); out.c[2]= NTSCg(p1); } out.c[0] * =0.6; return out; } lb #defιne RGBr(c) (c).r #defιne RGBg(c) (c).g #define RGBw(c) ((c).r+(c).g+(c).b) //================-====-=====-=======================—== COLOR VEC color_space_RGB(COLOR_RGB p1 , double Thresh_mdl) {COLORlVEC out={0,0,0};~ if((out.c[0]= RGBw(p1 ))>Thresh_mdl) {out.c[1]= RGBr(p1)/out.c[0]; out.c[2]= RGBg(ρ1)/out.c[0]; } out.c[0]*=0.33333333333333333*GAMMA; return out; } #define RGBSr(c) (c).r #defιne RGBSg(c) (c).g #defιne RGBSw(c) (c).b COLOR_VEC color_space_RGB_simple(COLOR_RGB p1, double Thresh mdl) {COLOR_VEC out={0,0,0}; out.c[0]= (RGBSr(p1 )>Thresh_mdl)?RGBSr(p1 ):0; out.c[1 ]= (RGBSg(p1 )>Thresh_mdl)?RGBSg(ρ1 ):0; out.c[2]= (RGBSw(p1 )>Thresh_mdl)?RGBSw(p1 ):0; return out; } /============__:=_=======_==_=====-====-=-__===-====__=====_== // #defιne NEWr(c) (0.4*((c).r+(c).g)-(c).b) // For interval normalisation 0.4 ->0.5 #define NEWr(c) (0.5 * ((c).r+(c).g)-(c).b) #defιne NEWg(c) ((c).r-(c).g) #define NEWw(c) ((c).r+(c).g+(c).b) p1 , double Thresh_mdl) if((out.c[0]= NEWw(p1 ))>Thresh_mdl) { out.c[1]= NEWr(p1 ); out.c[2]= NEWg(p1); // out.c[1 ]= NEWr(p1 )/out.c[0]; // out.c[2]= NEWg(p1)/out.c[0]; } out.c[0]*=0.6666666666666666; return out; } #defιne LMNr(c) (c).r #defιne LMNg(c) (c).g #defιne LMNw(c) (((c).r+(c).g+(c).b)*0.33333333333) #define Thresh J.UMINEN 136 ==================:==_=======__:==__:==:====_===__:===__:==:=_=_=__:===_== COLOR_VEC color_sρace_LUMIN_THR(COLOR_RGB p1, double Thresh mdl) {COLOR_VEC out={0,0,0}; double t; out.c[2]=out.c[1]=out c[0]= ((t=LMNw(p1 ))>Thresh_mdl)?t:0; return out; } //== = =================__========^^ const double SQ3= (sqrt(3.0)); const double PI05=(asin(1.0)j; #define min3(c) ( min((c).r, min((c).g,(c).b))) #define max3(c) ( max((c).r, max((c).g,(c).b))) #define IHSh(c.d) (atan (SQ3 * ((c).g-(c).b)/d)) #defιne IHSi(c) (((c).r+(c).g+(c).b)*0.33333333333) #defιne IHSs(c) ((double)(max3(c)-min3(c))/(double)(max3(c)+min3(c))) //==r========:====_=__:===__:__:_=__========:===== =_====__:======__:=:=^^ COLOR_VEC color_space IHS(COLOR RGB p1 , double Thresh_mdl) {COLOR_VEC out={0,0,0};~ double r=2 * p1.r-p1.g-p1.b; out.c[1]= IHSi(p1); out.c[2]= out.c[1]?IHSs(p1):0; ^e if(fabs(out.c[2])<Thresh_mdl) out.c[0]=0; else out.c[0]=r?IHSh(p1 ,r):(((p1.g-p1.b)<0)?-PI05:PI05); return out; } #include <stdlib.h> #include <stdio.h> #include <vmemory.h> #include<malloc.h> unsigned char far ** virtalloc(short xdim.short ydim) { int y.j; unsigned char far**mem; mem = (unsigned char__far**) malloc( ydim * sizeof(unsigned char __far**)); if(mem == NULL) return(NULL); for(y = 0; y < ydim; y++) { if ( (mem[y] = (unsigned char far * ) malloc(xdim * sizeof(char) )) NULL ) { printfC'NO MEMORY MAX size= %d",y); forG=0;j<y;j++) free((void *)memβ]); free((void*)mem); return(NULL); } } return(mem); } ORIGIN = PWB ORIGIN_VER = 2.0 PROJ = LNS CORR PROJFILE =INS_CORR.MAK BUILDDIR = obj DEBUG = 0 BRFLAGS = /o obj\$(PROJ).bsc BSCMAKE = bscmake SBRPACK = sbrpack NMAKEBSC1 = set NMAKEBSC2 = nmake BROWSE = 1 CC s cl CFLAGS_G = / 2 /BATCH /FR$ * .sbr IZ~ CFLAGS.D = /f /Zi /Od CFLAGS.R = /f- /Ot /Oi /OI /Oe /Og /Gs CXX = cl CXXFLAGS_G = /AL ΛΛ/4 /G2 /D_DOS /BATCH /FR$ * .sbr /Zn CXXFLAGS_D = /f- /Od /FPi87 /Zi /DMICI /DSINGLE WIN CXXFLAGS_R = /f- /Ot /Ol /Og /Oe /Oi /FPi87 /Gs /DMICI /DSINGLE WIN MAPFILEJD = NUL MAPFILE R = NUL LFLAGS_G = /NOI /STACK32000 /BATCH /ONERR0R:NOEXE LFLAGSJD = /CO /FAR /PACKC LFLAGS R = /EXE /FAR /PACKC LINKER = link ILINK = ilink LRF = echo > NUL ILFLAGS = /a /e LLIBS_G = graphics lafxcr CVFLAGS = /25 /S RUNFLAGS = ..\win4\S160_0 ..\win4\S160_ autol FILES = LNS_.CORR.CPP .ΛLIBWICALLOC.CPP ..\LlB\PROJCTN7.CPP\ ..\LIB\PIC_M7.CPP ..\LIB\RES_MCH7.CPP COR_ . FNC.CPP COR WIN.CPP OBJS " = objΛLNS CORR.obj objWICALLOC.obj obj\PROJCTN7.obj obj\PIC_M7.obj\ " obj\RES_MCH7.obj obj\COR_FNC.obj obj\COR_WIN.obj SBRS = objΛLNS CORR.sbr objWICALLOC.sbr obj\PROJCTN7.sbr obj\PIC_M7.sbr\ ~ obj\RES_MCH7.sbr obj\COR_FNC.sbr obj\COR_WIN.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp Bi obj\LNS_CORR.obj : LNS_CORR.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\io.h C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\MFC\INCLUDE\afx.inl ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\lin rn7.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\LNS_CORR.obj LNS_CORR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGSJ ) /Foobj\LNS_CORR.obj LNS_CORR.CPP « IENDIF objΛLNS CORR.sbr : LNS CORR.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\io.h C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\iostream.h\ C:\C700\MFC\INCLUDE\afx.h LNS_CORR.h cor_win.h c:\ilya\lib\vicalloc.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\lNCLUDE\ostream.h\ C:\C700\MFC\INCLUDE\afx. inl ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\lin trn7.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_.D) /FRobj\LNS_CORR.sbr LNS_CORR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\LNS_CORR.sbr LNS_CORR.CPP « 8a IENDIF objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjΛVICALLOC.sbr .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « IENDIF obj\PR0JCTN7.obj : .ΛLIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h .ΛLIB\projctn7.h\ C:\C700\INCLUD ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PROJCTN7.obj ..\LIB\PR0JCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /Foobj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « 1ENDIF obj\PROJCTN7.sbr : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PROJCTN7.sbr ..\LIB\PR0JCTN7.CPP « IENDIF obj PIC M7.obj : ..\LIB\PIC_M7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\malloc.h .ΛLIB\phdr.h\ c:\ilya\lib\vicalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « IENDIF objΛPIC M7.sbr : ..\LIB\PIC_M7.CPP C:\C700\INCLUDBstdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ c:\ilya\lib\vicalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « !ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « IENDIF obj\RES_MCH7.obj : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE memory.h ..\LIB\pic_mch7.h .ΛLIB\res_mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « .ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IENDIF $(CXXFLAGS_D) /FRobj\RES_MCH7.sbr .ΛLIB\RES_MCH7.CPP « 'ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « IENDIF objΛCOR FNC.obj : COR_FNC.CPP C:\C700\INCLUDE\stdio.h C:\C700\TNCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\float. H\ C:\C700\INCLUDE\graph.h cor nc.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDEWmemory.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp B5 /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COR_FNC.obj COR_FNC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COR_FNC.obj COR_FNC.CPP « 1ENDIF obj\COR_FNC.sbr : COR_FNC.CPP C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\float.H\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\COR_FNC.sbr COR_FNC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\COR_FNC.sbr COR_FNC.CPP « IENDIF objΛCORJ/VIN.obj : COR WIN.CPP C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h LNS.CORR.h cor_fnc.h ..\LIB\projctn7.h\ ..\LIB\pic_mch7.h .ΛLIB\res mch7.h c:\iiya\iib\Tin trn7.h\ C:\C700\INCLUDE\math.h " !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COR_WIN.obj COR_WIN.CPP « IELSE @S(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COR_WIN.obj COR_WIN.CPP « lENDIF obj\COR_WIN.sbr : COR_.WIN.CPP C:\C700\INCLUDE\vmemory.h\ θb C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h LNS_CORR.h corjnc.h ..\LIB\projctn7.h\ ..\LIB\pic_mch7.h ..\LIB\res_mch7.h c:\ilya\lib\TinJrn7.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\COR_WIN.sbr COR_WIN.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\COR_WIN.sbr COR_WIN.CPP « IENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) -f $(PROJFILE) obj\$(PROJ).bsc !IF $(DEBUG) $(LRF) @«obj\$(PROJ).lrf $(RT OBJS: = + Λ ) $(OBJS: = + ) $@ $(MAPFILE D) $(LIBS: = + Λ ) + $(LLIBS_G: = + Λ ) + $(LLIBS_D: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_D); « IELSE $(LRF) @«obj\$(PROJ).lrf $(RT OBJS: = + Λ ) $(OBJS: = + Λ ) $@ $(MAPFILE_R) $(LIBS: = + Λ ) + $(LLIBS_G: = + Λ ) + $(LLIBS_R: = + Λ $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « 1ENDIF $(LINKER) @obj\$(PROJ).lrf .cpp.obj : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Fo$@ $< « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Fo$@ $< « 1ENDIF .cpp.sbr : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FR$@ $< « lELSE @S(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FR$@ $< « 1ENDIF run: obj\S(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV$(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) void corr_win_ρroto(PCT win_source,PCT Proto, SCR_PNT win_size .short win_step, double CORR_THRESH, short *StripEnds) ; // Module calculates correlation functions of PROTO_1 and set of // prototypes. Set of prototypes' names is defined by a MASK correspondes // to names generated by MAKEPRB and has next structure: // [path]&RRW_P.rgb // Where // [path] - optional name of directory; // & - first letter of file name // RR - two digits corresponding to prototype's hight IX (RR= 16| 32 | 48 | 64) // W number corresponding to window number (see MAKEPRB // description. // P prototype Number // MASK includes ONLY [path]&RRW_ and programme will // calculate correlation functions for prototypes with P from 0 to // first not existing number. // COMMAND STRING // // lns_corr <PROTOJ_Name> <MASK> [CommandFile] // // <PROTO_1_Name> File name of PROTOTYPE without extention // <MASK> Mask for prototypes FileNames without extention and // Prototype's number. // [CommandFile] Optional ASCI file with a run time parameters. // // INPUT // RGB files of prototypes and corresponding .SGN files created by // module MAKEPRB. // RUN TIME parameters: // // 000 0 -shift for all cases have to be 0 // <CalorSpace> // We have used 1 - as worked only with a luminance // <Window width> // We have used 8 //SEE ALSO FILE "LNS CORR.INI" // OUTPUT // Correlation functions in PROTO DBC file. #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <graph.h> #include <float.H> 40 #include <io.h> #include <time.h> #include <ctype.h> #include <iostream.h> #include <afx.h> #include "LNS_CORR.h" #include "cor_win2.h" #include "vicalloc.h" char f_name[40]="J , ,FILE_name[40]="J' 1 FRAME_Name[40]-'_.", ARGVJ[30]="J', STRING name[40]=" ", SIGN__name[40]= , _",TAG_name[9]='_", drive[3]="J',dir[30]="J', ext[5]=" ", * tagjrame; double GAMMA=1.0,CORR_THRESH=0.0,Thresh_mdl=0.0; short MAP; short VO.TING=3,TAG_hight; struct _videoconfig vc; FILE *datres; int FLG_WRIGHT=0; double sh[4H0,0,0,0}; PCT pict arget, pict_proto; FILE * out_rslt; int picturejnf(char *name,SCR_PNT *vertexes); int picture inf_num(char *name,SCR PNT *vertexes,short n); int get_number(); // INITIALISATION GRAPHICMODE, GET SCALE int get_number_3(); // INITIALISATION GRAPHICMODE, GET SCALE void get shift _f(FILE f .double * sh); // INITIALISATION GRAPHICMODE, GET SCALE void get shift(double * sh); // INITIALISATION GRAPHICMODE, GET SCALE int get_number_3 f(FILE *f); // INITIALISATION GRAPHICMODE, GET SCALE int picturejnf_num_2(char *name,SCR_PNT *vertexes,short n.char *ext); int picturejnf_num_new(char *name,SCR_PNT * vertexes,short n); / /Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ φφφφφφφφφφφ φ φ φ φ Φ Φ Φ φ Φ Φ Φ Φ Φ Φ Φ φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ Φ //ψψψΨvWVψψψψψψψψψΨψψφψψψψΨ ΦΦΦΦ φ φφφφφ φ φφφ ΦΦΦΦ wψψψψψw ψψψψψψφψψy short PRESENT_HIGHT=32, CALC_HIGHT =32; FILE * INP PROTOCOL; FILE *PRC OCOL; CString PROTOCOL_NAME; CString PROTOCOL_START; CString PROTO1_HEADER=CString::CString( -U "PROTO File\tFRAME_Name\tSTRING_name\tS_name\tSLength\tWinLengt h\tSPACE\n"); CString PROTO_TAG_HEADER=CSt ng::CString( •TAG_File\tFRAME_Name\tSTRING_name\tS_Name\tLegnth\tCOMM\n"); void init_protocol(char "name) {short FLG; FLG= access(PROTOCOL_NAME,0); 110 if exist PRθ θCOL=fopen(PROTOCOL_NAME,"a"); if(FLG) fprintf(PROTOCOL,"AUTO and CROSS correlation functions \n %s", PROTO 1_HEADER); PROTOCOL START=name; PROTOCOL_START+="\t"; } //-==_================-=====================r=^ int open_inp_prot(char *name) {if(!(INP_PROTOCOL=fopen(name,"r"))) return 1; //split first str fscanf(INP_PROTOCO ,"%*[ Λ \n]s"); return 0; } / ///vΦ Ψ ΦvΦφΦψΦvΦψΦvΦΦφΦΦΦvΦwΦψΦψΦwΦψΦwΦψΦwΦψΦΦφψΦwΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦΦ φ ΦψΦφΦφΦφΦψΦψψΦφΦφΦφΦψφyφφφφφφψφψφφφφφφ //return file name without extwntion in "name" and TRUE 1 if file exist; int next_pict(char *name,char *mask,char *ext,int num) //if num—2 initalisation; // -1 next // >0 adding this # to mask // NULL if notexist file with ".rgb" {static int now; char full ιame[80]; strcpy(name,mask); if (num==-2)now=0; else if (num==-1 ) now++; else if (num<0) return 1 ; else now=num; Jtoa( now, name+strlen(name), 10); strcat(strcpy(full_name,name),ext); //1 if file exist return(! access( full_name, 0 )); } m #include <fstream.h> int ReadStrlnf(char *name,short * StD) {ifstream InpF; char a[80]; strcat(strcpy(a,name),".str"); short i; InpF.open(a,ios::in|ios::nocreate); if(lnpF.fail()) {InpF.clear(O); return 1 ; } lnpF.getline(a,80,'\n'); lnρF.getline(a,80,'\n'); lnpF.getline(a,80,'\n'); InpF.getlineia.δO.'vY); lnpF.getline(a,80,'\n'); lnpF.getline(a,80,'\n'); i=0; do { lnpF»StD[i++]; if (InpF.eofOH i>17) { StD[-φ=-1. break; } lnpF»StD[i++]; } while(1); lnpF.close(); return 0; } //= SCR PNT winsize; / ========_=====__:: int main(int argc.char* argvQ) {int FLG_F=0, FLG_WRIGHT=0; FILE * datainf; short winstep, map_stnd; short n=0; SCR_PNT t_pos; if((argc != 3) && (argc !=4)) { printf(" target-file proto file_mask \n"); FLG_F=0; retum(1); } ' else if(argc ==4) {FLG_F=1 ; if(!(datainf=fopen(argv[3],"r"))) return 0; } if(FLG_F) {get_shiftj(datainf,sh); // GET SCALE get number_3 f(datainf); // GET SCALE } else {get_shift(sh); // GET SCALE 0 get_number 3(); } strcpy(ARGV_1,argv[1]); PROTOC0L_NAME=argv[1]; PROTOC0L_NAME+=".dbc"; init_protocol(argv[1 ]); // =__===_=--_=======-== GRAPHICS START if(GRAPHICS_START(&vc.GRAPHM0DE)) exit(-1); //==___====== TARGET PICTURE name and vertexes SCR_PNT target_pos; // CONSTRACTOR default 0,0 short StrDescr[17]; _splitpath( argv[1], drive,dir,TAG_name,ext ); pictJarget=sign_storage_rgb(argv[1],vc ); if(ReadStrlnf(argv[1 J.StrDescr)) {printf("STR PROTO not exist"); GRAPH OUT(-1 );return -1 ; }; wiπsize.π=pictJarget.s_rows; winstep=winsize.c; //"PROTO File\tFRAME_Name\tSTRING name\tS name\SLength\tWinLengt h\tSPACE\n"); fprintf(PROTOCOL,"%s %8s\t%6s\t%12s\t%4d\t%4d\t%12s\n%s", (const char * )PROTOCOL_START,FRAME_Name,STRING_name,SIGN_name, pictJarget.s_cols,winsize.c,SP[MAP], (const char * ) PROTO_TAG_HEADER); //=.===_===== PROTOTYPE LOOP OVER names char proto_name[NAME_LENGTH],buff[4]; SCR_PNT proto_pos,z; //loop over masks //return file name without extention in "name" and TRUE 1 if file exist; short proto_number=0; //# 0; while( next_pict( proto_name,argv[2],".rgb", proto_number)) { proto_number=-1 ; //next; SCR_PNT pr_v[4]; // PROTO INFORMATION IN PROTOCOL pict_proto=sign_storage_rgb(proto_name,vc ); picturejnf_num_2(ρroto_name,pr_v,0,".str"); //only for SIGN_name // , TAG_.File\tFRAME_Name\tSTRING_name\tS_Name\tLegnth\n") fprintf(PROTOCOL," %12s\t %8s\t %6s\t %12s\t%4d\n", proto_name,FRAME_Name,STRING_name,SIGN_name,pict_proto.s_cols); TAG_hight=pict_proto.s rows; // TARGET PRESENTATION _clearscreen(J3CLEARSCREEN); proto_pos.c=target_pos.c=10; proto_pos. r=(target_pos . r= 10)+pict Jarget. SJΌWS+5; sign_present_RGB( pictJarget,target_pos); sign_present_RGB(pict_proto,proto θs); //= corr_win_proto(pictJarget, pict_proto, winsize, winstep,CORR_THRESH,StrDescr); pict_proto.free PCT(); } _displaycursor( J3CURSORON ); _setvideomode( _DEFAULTMODE ); pict target.free_PCT(); * fclose(PROTOCOL); retum(O); } // void get_shift f(FILE f.double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; for(i=0;i<4; i++) { fscanf(f,"%lf %lf\n",sh+i++,sh+i); } } // void get_shift(double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; cout« "vertexes shift over rows ( top right, bottonrwϊght, bottomjeft, topjeft %\n"; for (i=0;i<4; i++) cin»sh[i]; } -15 //=__======-_=-========================================== int get_number_3() // INITIALISATION GRAPHICMODE, GET SCALE {int R; _disρiaycursor( J3CURSORON ); ~setvideomode( " _ . DEFAULTMODE ); cόut « " [<0 EXiη, color nap (0-NTSC, 1-HSI.2-NEW.3-RGB.4- LUMIN_THR 5-HSI\n"; cout«"WIN_SIZE\n "; cin »MAP»winsize.c; _disρlaycursor( _GCURSOROFF ); _setvideomode( GRAPHMODE ); make_palette(); return R; } M «_l_l- 1. «_l.ι.ι *»*»<. » ι.ll__ι_ .l__ <.«««» int get number_3 f(FILE *f) // INITIALISATION GRAPHICMODE, GET SCALE {int R; fscanf(f," %d %d ",&MAP, &(winsize.c)); return 1 ; } //_======_=====-_=======__=___=======__==========__=__==== int picture Jnf (char *name,SCR_PNT *vertexes) {int i; char new_name[25]; FILE * datfp; strcat(strcpy(new_name,name),".sgn"); if(!(datfp=fopen(new_name,"r"))) return 0; fscanf(datfp,"%s\n",new_nanr_e); for(i=0;i<4;i++) f scanf (datf p, "%d %d\n", &( vertexes[i]. c), &(vertexes[i].r)); fclose(datfp); return 1; } //==========___=====================:_ //_===_ S __=______==_==_===:=____====__:^ int picturejnf_num 2(char *name,SCR PNT *vertexes, short n.char *ext=".sgn") {int i,j; char new_name[45]; FILE *datfp; strcat(strcpy(new_name,name),ext); if(!(datfp=fopen(new name,"r"))) return 0; fscanf(datfp,"%*s %*s %*s %*s %*s \n"); fscanf(datfp,"%s %s %s %s %s",&f_name,&FILE_name, &FRAME_Name, &STRING_name, &SIGN_name); forϋ=0;j<n+1;j++) for(i=0;i<4;i++) if(fscanf(datfp,"%d %d\n",&(vertexes[i].c),&(vertexes[i].r))==EOF) {fclose (datfp); return 0;} fclose(datfp); return 1 ; } === _ = _ = _ „= /*void write_signjnf(char * pr,PCT pict_now) { charfljp[50],f_name[9]; int FLG; FILE *dathere,*database; _splitpath( pr, drive,dir,f_name,ext ); strcat(strcpy(fl p,pr),".sgn"); dathere=fopen(flJp,"w"); FLG=_access("PROTODB.1", 0 );// -1 if not exist if(!(database=fopen("PROTODB.1","a"))) {strcpy(flJp,"CAN NOT CREATE D_BASE FILE"); exit(-1);} fprintf(dathere, " WIN_name FILE_name FRAME_Name STRING_name SIGN_name\n "); fprintf(dathere,"%8s %9s %10s %11s %9s \n",f_name, FILE_name, FRAME Name,STRING_ ame,SIGN_ ame); if(FLG) fprintf(database, " WIN name FILE name FRAME_Name STRING name SIGN_name\n "); fprintf(database,"%8s %9s %10s %11s %9s \n",f_name, FILE_name, FRAMEJteme,STRING_name,SIGN_name); fprintf(dathere,"%d 0\n",pict_now.s_cols-1 ); fprintf(dathere,"%d %d \n",pict_now.s_cols-1 ,pict_now.s_rows-1 ); fprintf(dathere," 0 %d\n",pict_now.s_rows-1); fprintf(dathere," 0 0\n"); fclose(dathere); fclose(database); } * / //_===============__:__:_:=======:=__==__:=_==_==_=_========_==_= //==========__:========__:======:=====__:===:===_===========_==^^ int picturejnf_num(char * name,SCR_PNT * vertexes,short n) {int i ; . char new name[25]; FILE * datfp; strcat(strcpy(new_name,name),".sgn"); if(!(datfp=fopen(new_name,"r"))) return 0; fscanf(datfp,"%s\n",new_name); for(j=0;j<n+1 ;j++) for(i=0;i<4;i++) if(fscanf(datfp,"%d %d\n",&(vertexes[i].c),&(vertexes[i].r))==EOF) {fclose (datfp); return 0;} fclose(datfp); return 1 ; } int picturejnf_num_new(char *name,SCR_PNT * vertexes,short n) {int i.j; char new_str[80]; FILE * datfp; int r,FLG=0; strcat(strcpy (new_str, name) , ". sgn"); 0; if(_Jscsymf( (int)new_str[0]))//FILE INFORMATIO ) //(letter or underscore) {sscanf(new_str," %s %s %s %s ",&FILE_name, &FRAME_Name, . &STRING_name, &SIGN_name)~ r=fscanf(datfp," %[ Λ \n]s ",new_str); } for(j=0;j<n+1 ;j++) for(i=0;i<4;i++) WFLG) if(fscanf(datfp," %[ Λ \n]s",new_str)==EOF) {fclose (datfp); return 0;} FLG=1; sscanf(new_str," %d %d",&(vertexes[i].c),&(vertexes[i].r)); } fclose(datfp); return 1; } //====_=====_==== : =_.==== = = = = S := = ==- === - = = = ==== = == s = ==== = ==== -^ } //— /*COLOR_VEC int_valueJ(PCT w.double Thr, COLOR_VEC ( * pJunct)(COLOR_RGB p1, double Thresh_mdl),AVERA " GE_VEC w_av) {COLOR VEC col,sum[9J[9],out,c1; const COLOR.VEC z={0,0,0}; short h ,vj,i,x,y,h,v, half_x=w.s_cols»1 ,half_y=w.s_rows»1 , quot_x=w.s__cols»2,quot_ =w.s_rows»2; long n; for(h=0;h<HOR_HARM+1 ;h++) for(v=0;v<VERT HARM+1;v++) sum[v][h].c[θT=sum[v][h].c[1]=sum[v][h].c[2]=0.0; n=w.s_cols * w.s_rows; n*=n; for(y=0;y<w.s ows;y++) for(v=0;v<VERT HARM+1;v++) { vj=y*((v+1)»1); vj=(vj+(v & 0x0001 ? quot_y:0))/half_y; vj &= 0x0001; _ f or(x=0;x<w. s_cόis;x++) {col=pJunct(w.get_pixel(y,x),Thr); d= sign for col(v t.col); for(h=0;h " <HOR HARM+1;h++) { h =x * ((h+1)»1); hj=(hj+(h & 0x0001 ?quot_x:0))/half x; h &= 0x0001; c1= signJor_col(hJ,d); for(i=0;i<3;i++) sum[v][h].c[i]+=c1.c[i]; } } } double s0,dd,max_v=0,th; for(dd=i=0;i<3;i++) {for(s0=h=0;h<HOR HARM+1;h++) ; out.c[ϊj=(dd?s0/dd:1); max_v=(max_v<out.c[i])?out.c[i]:max v; } ■ • ■ for(i=0;i<3;i++) {th=out.c[i]/max_v; // THRESHOLDING if(th<0.2) out.c[i]=0; } return out; > */ COLOR_VEC (*PointColFunct())(COLOR_RGB p1.double Thresh_mdl) { switch ( MAP) {case NTSC:return(color_space_NTSC); case New_plan:return(color_space_NEW); case HSI:return(color_space_RGB); case RGB:retum(color_space_RGB_simple); case LUMIN_THR:retum(color_spaceJ__UMIN_THR); case IHS:retum(color_spaceJHS); }; return WULL; } //=__= ^==:=__======:==:__=_=__=-^ const short CH_HIGHT D=100, CH BASE_D=^470, CH_HIGHT=100, CH_BAS " E=450, t_pos=40; =_==__==========__:=====_._=_======__:============_=====:= double scale act=1; //=====__=_====_====_.__=======:=__====__======_=______ void corr vin_proto(PCT win_source,PCT Proto, SCR_PNT win_size .short win step.double CORR THRESH.short * StripEnds) { short i; char mess[40]; short F=0; COLOR_VEC ( * pJunct)(COLOR_RGB p1, double Thresh_mdl); pJunct=PointColFunct(); PCT win(win_size.c,win_size.r); PCT tag(win_size.c,win_size r); SCR PNT stJ,st win; AVERAGE_VEC middle win[64],middle tag; const AVERAGE_VEC z={{0,0,0},{0,0,0}}; COLOR_VEC *corτ_now,cr; const COLOR_VEC z_col={0.0,0.0,0.0}; int Iine_size=win_source.s_cols+Proto.s_cols; //memory allocation loo if((corr_now= (COLOR_VEC * ) malloc( sizeof(COLOR_VEC)*(sizeJ)line_size * 3))==NULL) {printfC'WIN NOT MEMORY"); return;}; st .r=0; double dd; short StripStart.StripStop; short PartNum; k=PartNum=0; while(StripEnds[PartNum]>=0) {StripStart=StripEnds[PartNum++]; StripStop=StripEnds[PartNum++]; for (st_win.c=StripStart; st win.c+win_size.c<=StripStop;st_win.c+=win step,k++) { FLG_COL=1; for(i=0;i<line_size;corr_now[i++]=z_col); win.loadJemplate(win_source,st_win); middle_win[k]=average(win,Thresh_mdI,pJunct); #ifdef MICI #endif const COLOR_VEC z_UNIT={1.0,1.0,1.0}; for (stJ.c=0;stJ.c<=Proto.s_cols-win_size.c;st t.c++) { //=_____===:===:==:=====================-=========:==:= tag.load e plate(Proto.stJ); middle ag=average(tag,Thresh mdl.p unct); // DIFF ABS VALUES #ifdef SINGL_VAL cr=template conv 1 ( tag,win,Thresh_mdl,z_UNπ " .pJunct); strcpy(mess~' VECTOR Approach to * CORRELATION "); corr now[stJ.c]=Correlation_single_1(cr,middleJag,middle_win[k],z_ UNIT); #ifdef ABS VALUE strcpy(mess," DIFF ABS VALUES/ max ABS VALUES"); cr= template_abs_difM (tag,win,Thresh_mdl,z_UNIT,pJunct, middle_tag,middle_win[k]); #else cr=template conv_1( tag,win,Thresh_mdl,z_UNIT,pJunct); strcpy(mess? PEARSON CORR. "); corr now[stJ.c]=Correlation(cr,middleJag,middle_win[k],z UNIT); #endif ιo. #endif // ONLY LUMINANCE // strcat(mess," ALL 3 COMP"); strcat(mess," Only 0 COMP"); corτ_now[stj.c].c[1]=corτ_r.ow[st .c].c[2]= corr_now[st J. c]. c[0]; #ifdef MICI draw_color corr 1( corr_now[st t-c], , FLG_COL,CH_HIGHT_D,CH_BASE_D,CORR_THRESH, "" ~ stJ.c,Proto.s_cols); FLG_COL=0; #endif } //===_===FlLL PROTOCOL //$ WILL BE USED AS SEPARATOR FOR READING fprintf(PROTOCOL,"$\t%s\t$\t%4d\t $\n",mess, st_win.c); for(i=0;i<Proto.s cols;i++) //ONLY 0 COMP fprintf(PROTOCOL,"%6g\t",corr now[i].c[0]); fprintf(PROTOCOL," \n"); } } win.free_PCT(); tag.free_PCT(); free((void * )corr_now); return ; } //-===__=================:r=====_ = ==== ∞ //_===:=======:=__:==:=_===_:=:.=_====_=================:_===: void draw_chart(double *distJine,short n.double max value, short CH HIGHT, short CH_BASE,double THRESH. short t_pos) {short i,j; double p, crit=max_value; if(!max_value) for (i=0;i<n;i++) crit=(distjine[i]>cht)? distjine[i]:crit; else crit=max_ alue; if(!crit) crit=1; p= CH HIGHT*(1-THRESH/crit); _moveto( 0,CH_BASE-CH HIGHT ); . 08 SBRS = objWITCHSTR.sbr objWICALLOC.sbr obj\PROJCTN7.sbr obj\L_TRN7.sbr\ obj\PIC_M7.sbr obj\RES_MCH7.sbr objΛFILEMNP.sbr obj\MTCHTPL2.sbr\ obj\COR_FNC2.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp obj\MTCHSTR.obj : MTCHSTR.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\float.H C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\fstream.h\ matchng.h PIC_PRO.h MtchTpl2.h shift.h\ filemnp.h C:\C700\INCLUDE\iostream.h C:\C700\MFC\I NCLUDE\afx.inl\ c:\ilya\lib\mylib.h C:\C700\INCLUDE\direct.h ..\LIB\pic mch7.h\ ..\LIB\projctn7.h ..\LIB\res_mch7.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\MTCHSTR.obj MTCHSTR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\MTCHSTR.obj MTCHSTR.CPP « IENDIF obj\MTCHSTR.sbr : MTCHSTR.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\floatH C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\fstream.h\ C:\C700\MFC\INCLUDE\afx.h matchng.h PIC_PRO.h MtchTpl2.h shift.h\ filemnp.h C:\C700\INCLUDE\iostream.h C:\C700\MFC\INCLUDE\afx.inl\ I OS c:\ilya\lib\myiib.h C:\C700\INCLUDE\direct.h ..\LIB\pic_mch7.h\ ..\LIB\projctn7.h ..\LIB\res mch7.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsρ /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjΛMTCHSTR.sbr MTCHSTR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjΛMTCHSTR.sbr MTCHSTR.CPP « IENDIF objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsρ /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « 1ENDIF obj\PR0JCTN7.obj : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ /06 SBRS = obj ITCHSTR.sbr objWICALLOC.sbr obj\PROJCTN7.sbr obj\L_TRN7.sbr\ obj\PIC_M7.sbr obj\RES_MCH7.sbr objΛFILEMNP.sbr obj\MTCHTPL2.sbr\ obj\COR_FNC2.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp obj\MTCHSTR.obj : MTCHSTR.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\float.H C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\fstream.h\ C:\C700\MFC\INCLUDE\afx.h matchng.h PIC_PRO.h MtchTpIZh shift.h\ filemnp.h C:\C700\INCLUDE\iostream.h C:\C700\MFC\INCLUDE\afx.inl\ c:\ilya\lib\mylib.h C:\C700\INCLUDE\direct.h ..\LIB\pic_mch7.h\ ..\LIB\projctn7.h ..\LIB\res_mch7.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp • t, /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\MTCHSTR.obj MTCHSTR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj ITCHSTR.obj MTCHSTR.CPP « IENDIF obj\MTCHSTR.sbr : MTCHSTR.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\float.H C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\fstream.h\ C:\C700\MFC\INCLUDE\afx.h matchng.h PIC_PR0.h MtchTpIZh shift.h\ filemnp.h C:\C700\INCLUDE\iostream.h C:\C700\MFC\INCLUDE\afx.inl\ c:\ilya\lib\mylib.h C:\C700\INCLUDE\direct.h ..\LIB\pic_mch7.h\ ..\LIB\projctn7.h ..\LIB\res_mch7.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\MTCHSTR.sbr MTCHSTR.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjΛMTCHSTR.sbr MTCHSTR.CPP « IENDIF objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h CAC700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_RJ /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « lELSE @S(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « 1ENDIF obj\PR0JCTN7.obj : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ /06 C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PROJCTN7.obj ..\LIB\PR0JCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « 1ENDIF obj\PR0JCTN7.sbr : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h .ΛLIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « 1ENDIF obj\L_TRN7.obj : ..\LIB\L_TRN7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\malloc.h .ΛUB icalloc.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\pic_mch7.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\graph.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\L_TRN7.obj ..\L1B\L_TRN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) ιo ~ $(CXXFLAGS_R) /Foobj\L_TRN7.obj ..\LIB\L_TRN7.CPP « IENDIF ob j ΛL TRN7.sbr : ..\LIB\L TRN7.CPP C:\C700\INCLUDE\stdlib.h\ " C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\malloch .ΛLIBwicalloc.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\pic_mch7.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\graph.h UF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\L_TRN7.sbr ..\LIB\L_TRN7.CPP « .ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\L_TRN7.sbr ..\LIB\L_TRN7.CPP « IENDIF obj\PIC_M7.obj : ..\LIB_PIC_M7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.tι\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ .ΛUB icalloc.h ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « 1ENDIF obj\PIC_M7.sbr : ..\LIB\PIC M7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\s7dio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ ..VJB icalloc.h ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ /og ..\LIB\projctn7.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « IENDIF !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IENDIF objΛRES MCH7.sbr : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « IELSE @$(CXX) @«obj $(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « IENDIF objΛFILEMNP.obj : FILEMNP.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\sthng.h C:\C700\INCLUDE\io.h\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUDE\direct.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\time.h\ C:\C700\MFC\INCLUDE\afx. inl !IF $(DEBUG) l q @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjΛFILEMNP.obj FILEMNP.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjΛFILEMNP.obj FILEMNP.CPP « <? IENDIF ob j ΛFILEMNP.sbr : FILEMNP.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\io.h\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUD direct.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\time.h\ C:\C700\MFC\INCLUDE\afx.inl !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjΛFILEMNP.sbr FILEMNP.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjΛFILEMNP.sbr FILEMNP.CPP « IENDIF obj\MTCHTPL2.obj : MTCHTPL2.CPP C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float-H C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h matchng.h MtchTpl2.h cor_fnc2.h\ c:\ilya\Iib\mylib.h ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h PIC PRO.h ..\LIB\linJrn7.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\direct.h C:\C700\MFC\INCLUDE\afx.h filemnp.h\ C:\C700\INCLUDE\time.h C:\C700\MFC\INCLUDE\afx.inl !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /Foobj\MTCHTPL2.obj MTCHTPL2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsρ /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\MTCHTPL2.obj MTCHTPL2.CPP « 1ENDIF obj\MTCHTPL2.sbr : MTCHTPL2.CPP C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h matchng.h MtchTpl2.h corJncZhV c:\ilya\lib\mylib.h ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h PIC_PRO.h ..\LIB\linJrn7.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\direct.h C:\C700WlFC\INCLUDE\afx.h filemnp.h\ C:\C700\INCLUDE\time.h C:\C700\MFC\INCLUDE\afx.inl !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\MTCHTPL2.sbr MTCHTPL2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\MTCHTPL2.sbr MTCHTPL2.CPP « 1ENDIF obj\COR_FNC2.obj : COR FNC2.CPP C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h cor fnc2.h\ ..\LIB\pic_mch7.h ..\LIB\res_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COR_FNC2.obj COR_FNC2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COR_FNC2.obj COR_FNC2.CPP « 1ENDIF obj\COR_FNC2.sbr : C0R_FNC2.CPP C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\float. H C:\C700\INCLUDE\graph.h cor fnc2.h\ ..\LIB\pic_mch7.h ..\LIB\res_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\COR_FNC2.sbr COR_FNC2.CPP M l « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\COR_FNC2.sbr COR_FNC2.CPP « IENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) -f $(PROJFILE) obj\$(PROJ).bsc !IF $(DEBUG) GS_D); « IELSE $(LRF) @«obj\$(PROJ).lrf $(RT_OBJS: = + ) $(OBJS: = + Λ ) $@ $(MAPFILE_R) $(LIBS: = + A ) + $(LLIBS_G: = + Λ ) + $(LLIBS_R: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); << IENDIF $(LINKER) @obj\$(PROJ).lrf .cpp.obj : UF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Fo$@ $< « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Fo$@ $< « IENDIF .cpp.sbr : UF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FR$@ $< « 1ELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FR$@ $< « IENDIF run: obj\$(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV $(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) //return file name without extwntion in "name" and TRUE 1 if file exist; int next_pict(char *name,char *mask,char *ext,int num); //if num=-2 initalisation; -1 next >0 adding this # to mask and reinialise to this # NULL if notexist file with ".ext" short MaskDecoding(char *msk); //_=====_=-===-==.=============-_:-=-_-====-===== // _- B _____a_- B _ B _-___s__-____^^ CString MakeName(char *p ); CString MakeName(CString N); HH #ifndef MATCHNG #define MATCHNG #include "mylib.h" #defιne EXTANTION ".sg2" #defιne MaxProtoNum 40 #define MaxWinNum 40 #defιne PRESENT_HIGHT 32 #defιne MaxSignSize 256 // #define CALCULATION J-HGHT 16 #endif /»5 #ifndef TEMPLT #defιne MtchTPLT #include "projctn7.h" #include "pic_mch7.h" #include "res_mch7.h" #include "pic_pro.h" #define NTSC 0 #define HS1 1 #define New_plan 2 #defιne RGB 3 #defιne LUMIN_THR 4 #defιne IHS 5 class RsltNow {public: short voices; // voiting numbers double value; //value RsltNow: :RsltNow(){voices=0;value=0;} RsltNow: :RsltNow(short d.doubie v){voices=d;value=v;} }; //=========-_:==__:=================-========= class RSLT { public: RsltNow R; short pos; // position in string short ShNumb; short ProtoNum; short StrNum; RSLT::RSLT(){}; RSLT::RSLT(short num.short p, double v, short shft,short pro.short st) {R=RsltNow::RsltNow(num,v); pos=p; ShNumb=shft; ProtoNum=pro; StrNum=st; } }; double CalcCorrThresh(short * Hst.short HDim, short NPntAboveThr, int PlusThresh, double PrcntLvl=0); double CorrelationEstim(double C, double MinVal,double MaxVal, void*Addlnf=NULL); void MatchForProtoStr(PCT &T.PRT &P,SCR_PNT winsize.short winstep, double *CorrThresh, RsltNow "NowRslt, short * StripEnds); #endif ι\b #ifndef PIC_PRO #define PIC_PRO #include <stdlib.h> #include <direct.h> #include <afx.h> #include <pic_mch7.h> #include "filemnp.h" #defιne STR_MAX 4 const SCR_PNT z_0(0,0); class PRT:public PCT {public: //information CString PathName; CString FRAME_Number; CString STRING_name; CString SIGN_name; short Pos; // Position in the string long NumberOfChk,MaxNum; double * Charact; //models PRT::~PRT() {this->free_PCT(); Pos=0; ~ if(MaxNum) delete Charact; Charact=NULL; MaxNum=NumberOfChk=0; } II- PRT::PRT() {NumberOfChk=MaxNum=s_cols=s ows=0; Charact=NULL;pict=NULL; } //- PRT::PRT (short n_cols, short n_rows) {*(PCT *)this=PCT::PCT(n_cols,n ows); NumberOfChk=MaxNum=0; Charact=NULL; } int read_proto_SGN(char ext[]=".sgn") { CString new_name(' ',80); PathName=MakeName(PathName); new_name=PathName+ext; char now[80]; nη FILE *datfp; if(!(datfρ=fopen((const char*)new_name,"r"))) return 1 ; if(fscanf(datfp,"%*[ Λ \n]s ")==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; FRAME_N umber=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN_name=now; FRAME_Number.MakeUpper(); STRING_ ame.MakeUpper(); SIGN_name.MakeUpper(); fclose(datfp); return 0; ERR:fclose (datfp); return 1; } int proto_storage_rgb(char *name,struct_yideoconfig vc.char * ext=".sgn") {*(PCT *)this=sign_storage_rgb(name,vc); if ( I s_cols) return 1; PathName=MakeName(name); ' if (read_proto SGN(ext)) {free_PCf(); return 1 ; } return 0; } /_. int read_proto_DBC(FILE *datfp) { char now[80]; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;PathName=MakeName(now); if(fscanf(datfp,"%s ",now)==EOF)goto ERR;FRAME_Number=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN_name=now, if(fscanf(datfp,"%d ",&(this->s_cols))==EOF)goto ERR; FRAME_Number.MakeUpper(); STRING_name.MakeUpper(); SIGN_name.MakeUpper(); return 1; ERR: return 0; }_ int alloc_Charact_dbl(long Num) 11% { if(!(Charact=new double[Num])) return 1; MaxNum=Num; NumberOfChk=0; return 0: } II void free_Charact() {delete Charact; Charact=NULL; } II int readJ-haract_dbl(FILE * inp,long Num) {short i; double d; if(MaxNum<(NumberOfChk+Num)) return 1 ; for (i=0;i<Num;i++) {if(fscaπf(inp,"%lf ",&d) ==EOF) return 1; if(fabs(d)<1.0e-4) d=0; Charact[NumberOfChk]=d; NumberOfChk++; } return 0; } // double CorrValue(short WNum.short Pnum) {return ( * (Charact+(long)WNum*s cols+Pnum)); } //=-============== S ========:===^^ //======RETURN NUMBER OF STRIPS int read_target_SGN(SCR_PNT vrt[][4],char ext[]=".sgs") {int n=0,j,FLG,s; CString new_name(' ',80); PathName=MakeName(PathName); new_name=PathName+ext; char now[80]; FILE * datfp; if(!(datfp=fopen((const char*)new name.'V'))) return 1; if(fscanf(datfp,"% * [ Λ \n]s ")= " ^EOF)goto OUT; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; if(fscanf(datfρ,"%s ",now)==EOF)goto OUT;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto OUT; SIGN_name=now; if((s=PathName.ReverseFiπd( , \V))<0) s=PathName.ReverseFind(':'); FRAME_Number= PathName.Right(PathName.GetLengthO-s); STRING_name.MakeUpper(); SIGN_name.MakeUpper(); do{ for(j=0;j<4;j++) if((FLG=fscanf(datfp,"%d %d ",&(vrt[n]D].c),&(vrt[n]0].r)))==EOF) goto OUT; n++; } while(n<STR_MAX-1); OUT:fclose (datfp); return n; }; #defιne UnKnown -1 //=__=__====_=____==_= ===== __ = _=_^ typedef struct { short n; // voiting numbers short pos; // position in string double value; //value } RSLT_old; II void HistCollect(short NOfWin.short St.short Fin, PRT &Db); RSLT_old LineEstimation (short TagSize, PRT &Db,short NOfWin, short WSize, double Thr); int Linelnf(const PRT &P, PRT T, short rw, short Xpos.struct _videoconfιg vc); double Linlnter( PRT &P,short WNum.short WSize .double Pt); void HistThresh(short * H,short *BotThr,short TopThr.short num); #endif iQm V #include "Iin rn7.h" double VShift[][4]= { {0.0, 0.0, 0.0, 0.0} ,{-2,+2,+2,-2} ,{+2,-2,-2,+2} // ,{0.125,0,0,0.125} // ,{-0.125,0,0,-0.125} // ,{0,0.125,0.125.0} // .{0,-0.125,-0.125,0} // ,{0.125,0.125,0.125,0.125} // , {-0.125,-0.125,-0.125,-0.125} // }; //____========_====_= ,{0.1875,0,0,0.1875} //============== ,{-0.1875,0,0,-0.1875} //==.======__==_==__ {0,0.1875,0.1875,0} //=======__====== {0,-0.1875,-0.1875,0} // ,{0.1875,0.1875,0.1875,0.1875} // {-0.1875,-0.1875,-0.1875,-0.1875} // .{0.35,0.35,0.35,0.35} }; void VrtxCalculation(PRT &T,double sh[4],SCR_PNT NewV[4], SCR_PNT OldV[4]) {short j,k,MaxV; MaxV=T.s_rows; match_vertex( OldV); SCR PNT v[4]; /*===_=====_=__:= DIR_LINE top(OldV[3],OldV[0]),down(OldV[1],OldV[2]); DIR_LINE top_new,down_new; vertJor_map( * ((PCT *)(&T)),top,down,&top_new,&down_new); PT st1 =down_new.Start__p(),st2=toρ_new.Start_p(), endl =down_new.End_p(),end2=top_new.End_p(); PT SCR(st2,v[3]); PT SCR(end2,v[0]); PT_SCR(st1 ,v[1]); PT_SCR(end1 ,v[2]); match_vertex( v); =-===__=__============__=========*/ v[0]=OldV[0];v[1 ]=OldV[1 ];v[2]=OldV[2];v[3]=OldV[3]; //========:==-============================== : forO=0;j<4;j++) { NewV[j].c=vϋ].c; k=(ϋ%2)?j-1:j+1); if (fabs(shQ])<1 ) {NewVO].r=(shϋ]?(short)((vO].r-v[k].r) * shO])+ vD ' ]-r:v[j].r); } else NewV ].r=v[j].r+sr NewV[j].r= max(0, min(NewV[] " ].r,MaxV-1 )); } while((NewV[1 ].r-NewV[0].r)<8) {New\ [1 ].r=__min(NewV[1 ].r++,MaxV-1 ); if((NewV[1 ].r-NewV[0].r)<8) NewV[0].r= max(0, NewV[0].r-); } while((NewV[2]. r-NewV[3].r)<8) {NewV[2].r=_min(NewV[2].r++,MaxV-1); if((NewV[2].r-NewV[3].r)<8) NewV[3].r= max(0, NewV[3].r-); } } //_=============_===_.=======:====__==__=_===:__:===__:: All, #include <stdlib.h> #include <string.h> #include <io.h> #include <afx.h> #include <direct.h> //return file name without extwntion in "name" and TRUE 1 if file exist; int next_pict(char *name,char *mask,char * ext,int num) //if num=-2 initalisation; // -1 next // >0 adding this # to mask // and r einialise to this # // NULL if notexist file with ".ext" {static int now; char ful _name[80]; strcpy(name,mask); if (num==-2)now=0; else if (num==-1 ) now++; else if (num<0) return 0; else now=num; Jtoa( now, name+strien(name), 10); strcat(strcpy(full_name,name),ext); //1 if file exist return(!_access( full_name, 0 )); } //=__=_=__=r__=__=======__=__=:_.== ∞ short MaskDecoding(char *msk) {char * p,nm[40]; strcpy(nm.msk); if(p=strrchr( nm, (int) ΛY )) P+=2; else if(ρ=strτchr( nm, (int)':' )) p+=2; else p=nm+1 ; *(p+2)='\0'; return ((short)atoi( p )); } //===_====_====-============_===:_=_===_===:=_==:__:=_==:====== CString MakeName(CString N) { short k=(N.Sρanlncluding(" \t")).GetLength(); char * p,fp[80]; p=((char * )(const char * )N)+k; CString M=p; , ,3 if(M.Find(':')<0) { • rf(M.GetAt(0)=='\V) { M=':'+M; M= (char) getdrive( )-1+'A')+M; } else M= fullpath(fp,(const char *)M,80); } M.MakeLower(); return M; } //===_==_=____==:===:================= CString MakeName(char *p ) {CString M(p); return (MakeName(M)); } //-=_=======:====================== 13. J, #include <vmemory.h> #include <stdio.h> #iπclude <stdlib.h> #include <conio.h> #include <malloc.h> #include <float.h> #include <graph.h> #include <string.h> #include "matchng.h" #include "mtchtpl2.h" #include "corJnc2.h" #define MAX JJNE 1024 //extern short NumberOfWin; extern double GAMMA,Thresh_mdl; extern short MAP; extern short VOITING; extern struct _videoconfig vc; #define ProbValue(S,x) (2*(double)(x)/((S)-1.0)-1.0) void draw_color_corr_1 (COLOR_VEC corr.short F.double THRESH, short pos_now); //= double CalcCorrThresh(short * Hst.short HDim, short NPntAboveThr, int PlusThresh, double PrcntLvl) {double out; short sum=0,N=0,ist,incr; if (PrcntLvl) {for(ist=0;ist<HDim;N+=Hst[ist++]); NPntAboveThr=short (N*PrcntLvl+0.5); } II if(PlusThresh) {ist=HDim;incr=-1;} else {ist=-1;incr=1 ;} // POINT PARAMETER; do{ ist+=incr; sum+= * (Hst+ist); } while((sum<NPntAboveThr) && (ist>=0) && (ist<HDim)); out=ProbValue(HDim,ist); return out; } double CorrelationEstim(double C, double MinVal.double MaxVal, void*Addlnf) { if (C<MinVal) return MinVal; if (C>MaxVal) return MaxVal; return C; } COLOR_VEC (*PointCoIFunct())(COLOR_RGB p1, double Thresh_mdl) { switch ( MAP) {case NTSC:return(color_space_NTSC); case New_plan:return(color_space_NEW); case HSI:return(color_space_RGB); case RGB:return(color_space_RGB_simple); case LUMIN_THR:retu7n(color_space_LUMIN_THR); case IHS:return(color_space IHS); }; return NULL; } ===-=_==_=_===_===__=__=__-==_===_====_===========__==__-= const short CH_HIGHT=80, CH BASE=470; //-=_=====__==_===__=========__=====_=__===_===_=======_= void MatchForProtoStr(PCT &T.PRT &P,SCR_PNT winsize.short winstep, double *CorrThresh, RsltNow *NowRslt, short * StripEnds) { _setcolor( color num(0,0,0)); _rectangle( _GRLLINTERIOR,0,CH_BASE-3 * CH_HIGHT-(CH_HIGHT»1), vc.numxpixels ,CH_BASE ); double crmdl; short i; char mess[40]; short F=1; COLOR_VEC (*pJunct)(COLOR_RGB p 1, ouble Thresh_mdl); pJunct=PointColFunct(); // PCT win(winsize.c,winsize.r); // PCT tag(winsize.c.winsize.r); SCR ^ PNT stj,st_win; AVERAGE_VEC middle win.middle ag; const AVERAGE_VEC z^{{0,0,0},{0,0,0}}; COLOR_VEC cr; I3.b const COLOR_VEC z_col={0.0,0.0,0.0}; stj.r=0; st_win.r=0; short " k,StripStart,StripStop; double Value Now[ 1024]; // double *ValueNow=new double[P.s_cols+T.s_cols]; short PartNum; k=PartNum=0; while(StripEnds[PartNum]>=0) {StripStart=StripEnds[PartNum++]; StripStoρ=StripEnds[PartNum++]; for (st_win.c=StripStart; st win.c+winsize.c<=StriρStop;st_win.c+=winsteρ,k++) { F=1; middle_win=average2(P,Thresh_mdl,winsize,st_win,pJunct); const COLOR_VEC zJJNIT={1.0,1.0,1.0}; for(i=0;i<P.s_coTs+T.s_cols;ValueNow[i++]=0.0); for (st .c=0;st t.c<=T.s_cols-winsize.c;st t.c++) { short EndPointOfProNow= P.s_cols + st .c-st win.c; //=============-=======-=_====_====__=:====—===_====:_= middleJag=avefage2(T,Thresh mdl,winsize,st ,p unct); // DIFF ABS VALUES #ifdef SINGL_VAL cr=template_conv_2( T, P,Thresh_mdl,z_UN IT.winsize.st _t,st_win, pjunct); // strcpy(mess," VECTOR Approach to CORRELATION "); cr= Correlation_single_1 (cr,middleJag,middle_win,z_UNIT); crmdl=cr.c[0]; #else #ifdef ABS_VALUE // strcpy(mess," DIFF ABS VALUES/ max ABS VALUES"); cr= template_abs_diff_1 (tag,win,Thresh_mdl,z_UNIT,p_funct, middle ag,middle_win); #else cr=template conv_1( tag,win,Thresh_mdl,z_UNIT,pJunct); strcpy(mess? PEARSON CORR. "); cr=Correlation(cr,middle ag,middle_win,z_UNIT); crmdl=0.333333-(cr.c[0]+cr.c[1]+cr.c[2]); #endif #endif if (crmdl> CorrThresh[k]) imi ValueNow[EndPointOfProNow]=crmdl; draw_color coπr_1( cr, F,0.3,EndPointOfProNow); F=0; } double old=0,next,Val,now; next=ValueNow[0]; for(i=0;i<P.s_cols+T.s_cols;i++) { npw=next; next=(i==P.s_cols+T.s_cols-1 )?0:ValueNow[i+1 ]; Val= max( max(now.next).old); if(Val) {NowRslt[i].value+= Val; NowRslt[i].voices++; } old=now; } } } //==================== delete (ValueNow); return ; } void draw_color corr 1 (COLOR VEC corr.short F, double THRESH, " short pos now) { short j,k,l,i,st; static short pos_old; short POS; static COLORJ GB corr_old; POS=10+pos_now; _setcolor( color_num(240,240,240)); if(F) { corτ_pld.r=k=CH_BASE-2 * CH_HIGHT-40; st=CH_HIGHT/10; for(i=0;i<3;i++) { _moveto( 10,k-CH_HIGHT); Jineto(10,k); Jineto(10+vc.numxpixels,k); _moveto(10,k-CH_HIGHT * THRESH); Jineto(10+vc.numxpixels,k-CH_HIGHT * THRESH); fόr(l=0,j=1 ;j<11;j++) {l+=st; _moveto( (j==5)?5:((j==10)?0:7) ,k-l); Jineto(10,k-I); } k+=(CH HIGHT+20); } corr_old.g=corr__old.r+CH_HIGHT+20; coπ_ρld.b=corr_ ld.g+CH_HlGHT+20; pos old=10; } _setcolor( color_num(240,240,240)); k=CH_BASE; _moveto( pos_old,corr old.b); k-(short)(corr.c[2]*CH " HIGHT); Jineto((short)(POS) j); corr_old.b=j; k-=(CH_HIGHT+20); _moveto( pos_old,corτ_old.g); j=k-(short)(corr.c[1 ]*CH JHIGHT); Jineto((short)(POS),j); corr_pld.g=j; k-=(CH_HIGHT+20); moveto( pos_old,corr_dld.r); j^k-(short)(corr.c[0] * CH_HIGHT); Jineto((short)(POS) ,j); corτ_pld.r=j; pos_old=POS; } #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <graph.h> #include <float.H> #include <time.h> #include <ctype.h> #include <fstream.h> #include <afx.h> #include "matchng.h" #include "PIC_PRO.h" #inciude "MtchTpl2.h" #include "shift.h" #include "filemnp.h" #ifdef _DEBUG #defιne new DEBUG_NEW #endif //input Par //Files <frame>.RGB; frame>.sgs; <proto's>.RGB; <proto's>.hs2 short PlusThresnPnt; //Threshold for histogramme Number Of Points double MinimalVal; // for CorrThresh double MaximalVal; short HighVoiceThreshold=6; short median=0; short MAP=1; // Color Space short WinNum; double CorrThresh[MaxWinNum]; int lntroduction(int arg.char *a); short NumberOfWin.HistDim; CString BestName[2]={CString::CString(30),CString::CString(30)}; #define MaxNumberOfPoints 1024 RsltNow NowRsltfMaxNumberOfPoints]; short ReadHist(const char * PName,short * ** H); const short NumberOfShifts=sizeof(VShift)/(4*sizeof(double)); void FreeHist( short NOfWin.short ** H); void draw_DMF(RsltNow Now .short F.short CH_HIGHT,short CH_BASE, short pos_now,double scale); double GAMMA=1.0,CORR_THRESH=0.0,Thresh_mdl=0.0; short VOITING=3,TAG_hight; t3θ struct _videoconfig vc; ofstream LineC; const char clean[]=" /====:====:=:===-===-================r==:================ int ReadStrlnf(char * name, short * StD) {ifstream InpF; char a[80]; strcat(strcpy(a,name),".str"); short i; lnpF.open(a,ios::in|ios::nocreate); if(lnpF.fail()) {InpF.clear(O); return 1 ; } lnpF.getline(a,80,'\n'); lnpF.getline(a,80,'\n'); lnpF.getline(a,80,'\n'); InpF.getlineia.δO/Xn'); lnpF.getline(a,80,'\n'); lnpF.getline(a,80,'\n'); i=0; do { lnpF»StD[i++]; if (InpF.eofOH i>17) { StD[-i]=-1; break; } lnpF»StD[i++]; } while(1); lnpF.close(); return 0; } //=================_======_====_====__==; void PUT_NO_MATCH(void) { _settextposition( vc.numtextrows-2,0); _outtext( clean ); _settextposition( vc.numtextrows-2,0); outtext( "NO MATCH" ); } //==============================_=_ ==: void FillProtocol(char * m,short StrN, const char * name, RSLT now, int AskMess) {char mess[40],*p; LineC« StrN«" \t"«name«" \t"«now.ShNumb«" \t"«now.pos«" \t"« now.R.voices«" \t"«now.R.value«" \t"; /3 i if (AskMess) {if(now.R. value) { _settextposition( vc.numtextrows-2,0); _outtext( clean ); _settextposition( vc.πumtextrows-2,0); sprintf(mess," %s V=%6g N=%2d",m,now.R.value,now.R. voices); _outtext(mess ); p=mess; - while(!isspace( (int)(*p++=(char)getche()) )); * (-p)= , \0'; LineC«" \t"«mess; } else LineC«" \t NO MATCH"; } LineC«"\n"; } void PresentRslt(char *m,PRT &T.RSLT &R,SCR_PNT * V, short hight,short row_n, char *p msk, short CL) { SCR PNT p_p(10,row n); if(R.R. value) { if(CL) { _setcolor( color_num(0,0,0)); _rectangle( _GFILLINTERIOR,0,p_p.r, 680,p_p.r+36); } _setcolor( color_num(240,240,240)); PCT t_map=linearJransforττ.(T,V,hight); //PCT t_map=linearJraπsform_ > cont(T,V,hight); sign_present_RGB( t_map,p_p); t_map.free_PCT; p_p.r+=20; char p name[40]; PRT P; next_pict(p_name,p_msk,".rgb",R.ProtoNum); if(P.proto_storage_rgb(p_name,vc,".str")) {printfC'RGB PROTO not exist"); GRAPH_OUT(-1 ); }; p_p.c=10+R.pos-P.s_cols; sign_present_RGB( P,p_p); . FillProtocol(m,R.StrNum,(const char * ) P.SIGN_name, R.TRUE); /3a P.free PCT; } else { PUT_NO_MATCH(); } } //====================================================== CString PROTOCOL_NAME; //============ OpenLineCollection void OpenLineCol(const char * name) { LineC.open(name,ios::out|ios::app|ios::nocreate); if(LineC.fail()) {LineC.clear(O); LineC.open(name,ios::out|ios::app|ios::noreplace); if(ϋneC.fail()) {LineC.clear(O); cout « "CAN NOT OPEN FILE "«name; GRAPH_OUT(-1); } } } //====================================================_. int main(int argc.char * argv[]) { short * * Hist; const int PlusDir= TRUE; short StrDescr[17]; // ONLY 6 partition for string if(lntroduction(argc,argv[argc-1])) return-1 ; short CalcHight=MaskDecoding(argv[2]); // PROTOTYPE HIGHT // ======= GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) GRAPH_OUT(-1); PROTOCOL_NAME=argv[1 ]; PROTOCOL_NAME+=".mch" ; OpenLineCol((const char * )PROTOCOL_NAME); //================= TARGET LOADING & MEMORY PARAMETERS DEFINITION PRT TARGET; PRT PROTO; PCT target_map; const SCR__PNT proto_pos(10,30),target_pos(10,10); .33 SCR PNT TARGET_vrt[STR_MAX][4],NewVrt[STR_MAX][NumberOfShifts][4]; if(TARGET. proto storage_rgb(argv[1 Jvc)) {printfC'RGB TARGET not exist"); GRAPH_OUT(-1 ); return -1 ; } int NumberOfStrips=TARGET.readJarget_SGN(TARGET_vrt,EXTANTION); LineC« " MAP \tPlusThresnPnt MΪnimalVal MaximalVal \n"; LineC«MAP«" \t"«PlusThresnPnt«" \t"«MinimaiVal «" \t"«MaximalVal«" \t"«median« , \n'; LineC« "File \t"« argv[1]«" \t "«TARGET.SIGN_name«"\n"; LineC« "S# \t PROTO \t Sh \t Pos \t V \t Value \t R~es\n"; if(!NumberOfStrips) {LineC«"Did NOT find strips\n"; LineC.closeO; printf("Did not find lines"); GRAPH JDUT(-I); return -1 ; } char proto_name[40]; , short ProtoNumber=0; RSLT BestRslts[2]; BestRslts[0]=RSLT::RSLT(0,0,0,-1,0,0); BestRslts[1 ]=RS1T::RSLT(0,0,0,-1 ,0,0); RSLT BestNowRslts[2]; // New Vertexes Calculation short StripNumber; short ShiftNumber; for(StripNumber=0;StripNumber<NumberOfStrips;StripNumber++) for(ShiftNumber=0;ShiftNumber<NumberOfShitts;ShiftNumber++) // return NewVrt after reordering VrtxCalculation( TARGETNShift[ShiftNumber] l NewVrt[StripNumber][ShiftNumber], TARGET_yrt[StripNumber]); // LOOP OVER STRIPS for(StripNumber=0;StripNumber<NumberOfStrips;StripNumber++) { // LOOP OVER PROTOTYPE short ProtoNumber=0; while(next_pict(ρroto_name,argv[2],".rgb",ProtoNumber)) // RGB proto EXIST { // LOCAL QUALITY BestNowRslts[0]-RSLT::RSLT(0,0,0,-1,0,0); BestNowRslts[1]=RSLT::RSLT(0,0,0,-1,0,0); //==========Proto Loading if(PROTO.proto storage rgb(proto_name,vc,".str")) {printf("RGB PROTO not exist"); GRAPH_OUT(-1);returπ -1; }; _clearscreen( _GCLEARSCREEN ); sign_present_RGB( PROTO,ρroto_pos); if(ReadStrlnf(proto_name,StrDescr)) {printf("SGN PROTO not exist"); GRAPH OUT(-1 ); return -1; }; t //========== HIST reading CString HNameC-',60); HName=proto name; HName+=".hs2": // here read size of windows from Hist and so on SCR_PNT WinSize; short winstep, NoHist; WinSize.r=CalcHight; NoHist=0; if(!(WinSize.c=ReadHist((const char * )HName,&Hist))) {printf("Did not find Hist %s",proto_name); NoHist=1; WinSize.c=8; NumberOfWin=MaxWinNum;} winstep=WinSize.c; // MEMORY ALLOCATION & inicialisation FOR Decision Making short i; for (i=0;i<MaxWinNum;CorrThresh[i++]=-1.0); for (i=0;i<NumberOfWin;i++) {if(NoHist) CorrThresh[i]=0.3; else { CorτThresh[i]=CalcCorrThresh( * (Hist+i),HistDim, PlusThresnPnt,PlusDir,0); CorrThresh[i]=CorrelationEstim(CorrThresh[i], MinimalVal, MaximalVal.NULL); } } if(! NoHist) FreeHist( NumberOfWin, Hist); // !!!!!!! CorrelationThreshold for all windows short NumberOfPoints: //============= LOOP OVER SHIFTS for(ShiftNumber=0;ShiftNumber<NumberOfShifts; ShiftNumber++) {if(NewVrt[StripNumber][ShiftNumber][0].r<0) continue; »35 target_map=linearJransform(TARGET, // target_map=linear_transform_cont(TARGET, NewVrt[StripNumber][ShiftNumber].CalcHight ); Number0fPoints=PROT0.s_cols+target_map.s_cols; _setcolor( color_num(0.0,0)); _rectangle( J3FILLINTERIOR,0,0, vc.numxpixels ,proto_pos.r-1); sign_present_RGB( target_maρ,target_pos); //— Result Initialisation For Every SHIFT for(i=0;i<MaxNumberOfPoints;i++) NowRslt[i]=RsltNow::RsltNow(); //========== Proto Calculation MatchForProtoStr(target_map, PROTO, WinSize, winstep, CorrThresh,NowRslt,StrDescr); target_map.free_P CT(); //correct filling The BEST For Shift, Proto, Strip #ifdef MYDEBUG double scale=-1 ; for(i=0;i<NumberOfPoints;i++) scale= max(scale, NowRslt[i]. value); #endif for(i=0;i<NumberOfPoints;i++) { if( NowRslt[i].value>BestNowRslts[0].R. value) { //=================== Not repeat small shifts if(abs(i-BestNowRslts[0].pos)>=4) BestNowRslts[1]=BestNowRslts[0]; BestNowRslts[0].pos=i; BestNowRslts[0]. R=NowRslt[i]; BestNowRslts[0].ShNumb=ShiftNumber; BestNowRslts[0].ProtoNum=ProtoNumber; BestNowRslts[0].StrNum=StripNumben jf(BestNowRslts[0].R.voices>=HighVoiceThreshold) {BestRslts[0]=BestNowRslts[0]; BestRslts[1 ]=RSLT::RSLT(0,0,0,-1 ,0,0); PR0TO.free_PCT(); BestName[0]=PROTO.SIGN name; goto DIRECT_DECISION; } } else if( (NcwRslt[i].value>BestNowRslts[1].R. value) && (aDs(i-BestNowRslts[0].pos)>=4)) { BestNowRslts[1 ].pos=i; (36 BestNowRslts[1 ].R=NowRslt[i]; BestNowRslts[1].ShNumb=ShiftNumbeπ BestNowRslts[1].ProtoNum=ProtoNumber; BestNowRslts[1].StrNum=StripNumber; } } // May be presentation for analyses #ifdef MYDEBUG short F=1; short CH_HIGHT=100, CH_BASE=190; _setcolor( color num(0,0,0)); _rec-tangle( _GFILLINTERIOR,0,CH_BASE-CH_HIGHT, vcnumxpixels ,CH_BASE ); if(scale) { for(i=0;i<NumberOfPoints;i++) {drawJ}MF(NowRslt[i] ,F, CH_HIGHT, CH_BASE, i-PROTO.s cols, scale); F=0; } #ifndef RUN getch(); #endif } else PUT_NO_MATCH(); #endif } // Shift closed PROTO.free_PCT(); ProtoNumber++; //==========PROTOC0L PROTO OUTPUT========================================= #ifdef MYDEBUG short pp2=10,CL2=TRUE; for (i=0;i<2;i++) { PresentRslt("PROTO SHIFT RSLT?",TARGET,BestNowRslts[i], NewVrt[BestNowRslts[i].StrNum][BestNowRsIts[i].ShNumb], CalcHight,pρ2,argv[2],CL2); CL2=FALSE; pp2=50; } #else FillProtocolfPROTO SHIFT RSLT?", StripNumber, (const char * ) PROTO.SIGN_name, BestNowRslts[0],FALSE); #endif // GLOBAL MAX for(i=0;i<2;i++) if( BestNowRslts[i].R.value>BestRslts[0].R. value) {BestRslts[1 ]=BestRslts[0]; BestRslts[0]=BestNowRslts[i]; BestName[1 ]=BestName[0]; BestName[0]=PROTO.SIGN_name; } else € if( BestNowRslts[i].R.value>BestRslts[1].R. value) {BestRslts[1 ]=BestNowRslts[i]; BestName[1]=PROTO.SIGN name; } II- } //Proto closed } //Strips Closed // GLOBAL PROTOCOL OUTPUT DIRECT_DECISION: #ifdef MYDEBUG short i; short Rows_n=10,Blanc=TRUE; ?", BestRslts[i].ShNumb] I } #else FillProtocol("GLOBAL RSLT ?"„(const char * )BestRslts[0].StrNum, (const char * ) BestName[0]; BestRslts[0],FALSE); #endif // LineC.closeO; TARGET.free PCT(); GRAPH_OUτ7θ); return 0; } //========================================================== short ReadHist(const char *PName,short *** H) {char p[80]; ifstream HFile; HFile.open(PName,ios::in|ios::nocreate); if(HFile.failO) {HFile.clear(O); cout « "CAN NOT OPEN FILE "«PName«"\n"; return 0; } HFile.getline(p,80); // LineC«"Histogrammes\n"; HFile.getline(p,80); //«argv[1]«"\t"«prototype.SIGN_name«'\n'; HFile»ρ»NumberOfWin; // «NumberOfWin«'\n'; HFile»ρ»HistDim; //"NumberOfBins-1\t"«HistDim«'\π'; HFile.getline(p,80); //"Win_pos\n"; HFile.getline(p,80); //"Win_pos\n"; (*H)= new (short( * [NumberOfWin])); short n.jj.WindowSize; for (i=0;i<NumberOfWin;i++) (*H)[i]=new short[HistDim]; forO=0;j<NumberOfWin;j++) {ifϋ==1) HFiie»WindowSize; else HFile»n; for(i=0;i<HistDim;i++) HFile»( * H)β][i]; } HFile.close(); return(WindowSize); } //========================================================== void FreeHist( short NOfWin, short * * H) {short i; for (i=0;i<NOfWin;i++) delete H[i]; delete H; } // int get_number_match() // INITIALISATION GRAPHICMODE, GET SCALE { GRAPH_OUT(); cout « " MAP PlusThresnPnt MinimalVal MaximalVal HighVoiceThreshold median \n"; cin »MAP»PlusThresnPnt»MinimalVal»MaximalVal»HighVoiceThreshold »median; II „ .»._----.-._ GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) GRAPH_OUT(-1 ); //================= return 1 ; } //""" int get number_match f(FILE * f) // INITIALISATION GRAPHICMODE, GET SCALE { fscanf(f," % * [ Λ \n]s "); fscanf(f," %d %d %lf %lf %d %d",&MAP,&PlusThresnPnt,&MinimalVal,&MaximalVal, &HighVoiceThreshold,&median); // Threshold for histogramme Number Of Points // for CorrThresh return 1 ; } //===================INTRODUCTlON int lntroduction(int arg, char * a) { int FLG_F=0; FILE * datainf; short n=0; if((arg != 3) && (arg !=4)) { printf(" target-file proto_fiie_ > mask\n"); FLG_F=0; return(1); } else if(arg ==4) {FLG_F=1; if(!(datainf=fopen(a,"r"))) return 0; } if(FLG_F) {get_number_matchj(datainf); // GET SCALE AND PARAMETERS fclose (datainf); } else get_number_match(); return 0; } // Graphic Output I HO void draw_DMF(RsltNow Now .short F.short CH HIGHT, short CH_BASE, short pos_now, double scale) { short j,k,l,st; static short real_size,pos_ ld; short POS; static double old_Y; POS=10+pos_now; _setcolor( coiorjιum(240,240,240)); if(F) { old Y=k=CH_BASE; st=CH HIGHT/10; _moveto( 10,k-CH_HIGHT); Jineto(10,k); Jineto(680,k); moveto(10,k-CH HIGHT); Jineto(680,k-CHjHIGHT); for(l=0,j=1;j<11;j++) {l+=st; _moveto( O==5)?5:(ϋ==10)?0:7) ,k-l); Jineto(10,k-I); } pos old=10; } _moveto( pos_old,old Y); j=CH_BASE-(short)(Now.value*CH HIGHT/scale); Jineto((short)(POS),j); old_Y=j; pos old=POS; } //============================================== mi ORIGIN = PWB ORIGIN VER = 2.0 PROJ = STRNEW PROJFILE = STRNEW.MAK BUILDDIR = obj DEBUG = 1 BRFLAGS = /o obj\$(PROJ).bsc BSCMAKE = bscmake SBRPACK = sbrpack NMAKEBSC1 = set NMAKEBSC2 = nmake BROWSE = 1 CC = cl CFLAGSJ3 = ΛΛ/2 /BATCH /FR$ * .sbr Zn CFLAGS D = /f /Zi /0d CFLAGS_R = /f- /Ot /Oi /Ol /Oe /Og /Gs CXX = cl CXXFLAGS_G = /AL ΛΛ4 /G2 /D_DOS /BATCH /FR$ * .sbr /Zn CXXFLAGS.D = /f- /0b1 /Od /FPi87 /Zi /DMYDEBUG /DRUN /D DEBUG CXXFLAGS_R = If- /Os /Ol /Og /Oe /Oi /FPi87 /Gs /DMYDEBUG " DRUN MAPFILE D = NUL MAPFILE R = NUL LFLAGS " G = /NOI /STACK:32000 /BATCH /ONERROR:NOEXE LFLAGS D = /CO /FAR /PACKC LFLAGS R = /EXE /FAR /PACKC LINKER = link ILINK = ilink LRF = echo > NUL ILFLAGS = /a /e LLIBS.R = LAFXCR LLIBS_D = LAFXCRD LLIBS_G = graphics CVFLAGS = /25 /S RUNFLAGS = TST\t10284o plnew.ini FILES = COR_FNC8.CPP PIC M8.CPP VICAL8.CPP RES_MCH8.CPP PROJCTN8.CPP\ COMP_FNC.CPP STRNEW.CPP OBJS = obj\COR_FNC8.obj obj\PIC_M8.obj obj\VICAL8.obj objΛRES MCH8.obj\ obj\PROJCTN8.obj obj COMP FNC.obj objΛSTRNEW.obj SBRS = obj\COR_FNC8.sbr obj\PIC_M8.sbr obj\VICAL8.sbr obj\RES_MCH8.sbr\ obj\PROJCTN8.sbr obj\COMP_FNC.sbr obj\STRNEW.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp obj\COR_FNC8.obj : C0R_FNC8.CPP C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\float.h C:\C700\INCLUDE\graph.h cor_fhc8.h projctn8.h\ pic_mch8.h res_mch8.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\vmemory.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COR_FNC8.obj COR_FNC8.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COR_FNC8.obj COR_FNC8.CPP « IENDIF obj\COR_FNC8.sbr : COR_FNC8.CPP C:\C700\INCLUDBstdio.h\ C:\C700\INCLUDBstdlib.h C.\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\float. h C:\C700\INCLUDE\graph.h cor_fhc8.h projctn8.h\ pic_mch8.h res_mch8.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\vmemory.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\COR_FNC8.sbr COR_FNC8.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\COR_FNC8.sbr COR_FNC8.CPP « IENDIF objΛPIC M8.obj : PIC_M8.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\io.h\ C:\C700\INCLUDE\fcntl.h C.\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.h C:\C700\INCLUDE\mailoc.h phdr.h vical8.h\ pic_mch8.h C:\C700\INCLUDE\vmemory.h projctnδ.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) W3 $(CXXFLAGS_D) /Foobj\PIC_M8.obj PIC_M8.CPP « I ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PIC_M8.obj PIC_M8.CPP « IENDIF obj\PIC_M8.sbr : PIC_M8.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\io.h\ C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\fioat.h C:\C700\INCLUDE\malloch phdr.h vica!8.h\ pic_mch8.h C:\C700\INCLUDE\vmemory.h projctnδ.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsρ /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PIC_M8.sbr PIC_M8.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PIC_M8.sbr PIC_M8.CPP « IENDIF objΛVICALβ.obj : VICAL8.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\VICAL8.obj VICAL8.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\VICAL8.obj VICAL8.CPP « IENDIF obj\VICAL8.sbr : VICAL8.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\VICAL8.sbr VICAL8.CPP « IELSE @$(CXX) @«cbj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRcbj\VICAL8.sbr VICAL8.CPP « IENDIF obj\RES_MCH8.obj : RES_MCH8.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h res_mch8.h C:\C700\INCLUDE\graph.h\ projctnδ.h pic_mch8.h C:\C700.INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH8.obj RES_MCH8.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\RES_MCH8.obj RES_MCH8.CPP « IENDIF obj\RES_MCH8.sbr : RES_MCH8.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDBvmemory.h res_mch8.h C:\C700\INCLUDE\graph.h\ projctnδ.h pic_mchδ.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRcbj\RES_MCHδ.sbr RES_MCHδ.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\RES_MCHδ.sbr RES_MCHδ.CPP « IENDIF obj\PROJCTNδ.obj : PROJCTNδ.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h projctnδ.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«cbj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PROJCTN8.obj PROJCTN8.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PROJCTN8.obj PROJCTNδ.CPP « IENDIF objΛPROJCTNδ.sbr : PROJCTNδ.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDBstdlib.h C:\C700\INCLUDBiostream.h projctnβ.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDBostream.h\ C:\C700\lNCLUDBmath.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjΛPROJCTNδ.sbr PROJCTNδ.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjΛPROJCTNδ.sbr PROJCTNδ.CPP « IENDIF obj\COMP_FNC.obj : COMP_FNC.CPP comp nch projctnδ.h C:\C700\INCLUDE\math.h\ . C:\C700\INCLUDE\graph.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COMP_FNC.obj COMP_FNC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COMP_FNC.obj COMP_FNC.CPP « IENDIF objΛCOMP FNC.sbr : COMP_FNC.CPP compjnch projctnδ.h C:\C700\IN~CLUDE\math.h\ C:\C700\INCLUDE\graph.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\COMP_FNC.sbr COMP_FNC.CPP « !ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\COMP_FNC.sbr COMP_FNC.CPP « IENDIF objΛSTRNEW.obj : STRNEW.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDBfloat.h\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUDBfstream.h\ C:\C700\INCLUDE\time.h mylibmd.h comp fnch corJnc8.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\iostream.h projctnδ.h pic_mchδ.h res_mch8.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h C:\C700\INCLUDE\vmemory.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjΛSTRNEW.obj STRNEW.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjΛSTRNEW.obj STRNEW.CPP « IENDIF objΛSTRNEW.sbr : STRNEW.CPP C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDBfloat.h\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUDBfstream.h\ C:\C700\INCLUDE\time.h mylibmd.h comp fnch corJncδ.h\ C:\C700\INCLUDE\ctype.h C:\C700\MFC\INCLUDE\afx.inl\ C:\C700\INCLUDE\iostream.h projctnδ.h pic mchδ.h res_mch8.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h C:\C700\INCLUDE memory.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\STRNEW.sbr STRNEW.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) N ~ $(CXXFLAGS_R) /FRobjΛSTRNEW.sbr STRNEW:CPP « IENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) -f $(PROJFILE) obj\$(PROJ).bsc !IF $(DEBUG) $(LRF) @«obj $(PROJ).lrf $(RT OBJS: = + ) $(OBJS: = + Λ ) $@ $(MAPFILE D) $(LIBS: = + ) + $(LLIBS G: - * ) + $(LLIBS_D: = + ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_D); « IELSE $(LRF) @«obj\$(PROJ).Irf $(RT_OBJS: = +* ) $(OBJS: = + ) $@ $(MAPFILE_R) $(LIBS: = + Λ ) + $(LLIBS G: = + ) + $(LLIBS_R: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « IENDIF $(LINKER) @obj\$(PROJ).lrf .cpp.obj : !IF $(DEBUG) m @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoS@ $< « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoS@ $< « IENDIF .cpp.sbr : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FR3@ $< « ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FR$@ $< « IENDIF run: obj\$(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV $(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) 11 // LINE SELECTION // COMMAND STRING // // Ins corr <TARGET_name> [CommandFile] // // <TARGET_name> File name of FRAME without extention // [CommandFile] Optional ASCI file with a run time parameters. // // INPUT // RGB files of frame (field) and corresponding .SGN files created by // module PLINE. // RUN TIME parameters: // //fscanf(f," %d %d %d",&MinSIoρe,&MaxSlope,&SloρeStep,); //SEE ALSO FILE "PLiNes.ini" // OUTPUT // TARGET_name.stp - all local max lines; // TARGET_ .ame.pn2 - lines after cleaning selected; // TARGET_name.pln - Strips selected; // LINEDET.002 - result collection for analises, // includes keyboard information for analyse. #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <graph.h> #include <float.H> #include <afx.h> #include <f stream. h> #include <time.h> #include "mylibmd.h" #include "COMP_FNC.h" #include "COr_FNCS.h" #include <ctype.h> short MaxStripNumber= 16; short DistanceThresh=10; short DetectorWidthPlus=4; short MinSlope=-20, MaxSlope=20, SlopeStep=2; GOODJDIRJ.INE __huge Lines[300J; AVERAGE_VEC huge AverageForLines[300]; struct _videoconfig vc; double GAMMA=1.0,CORR THRESH=0,Thresh_mdl=0; short VOITING=0,MAP=0; char f_name[40]=" ".FILE name[40]=" ", FRAME Jame[40]=" "; ISO PCT pictjarget, targe jτιap; void WriteLines(GOOD_DIRJ NE * L,short MaxN, const char * name); void WritePears(GOOD_DIRJ_INE * L,short MaxN, const char * name,short PMax); int cdecl compare_array_elem ( const void * elem1, const void * elem2 ); int lntroduction(int arg, char * a); ofstream LineC; //============================================ int main(int argc.char * argv[]) {short i,j; char *p,mess[128], cleanQ= H "; if(lntroduction(argc,argv[argc-1 ])) retum-1 ; // PROTOCOL OUTPUT // ================ GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) GRAPH_OUT(-1 ); //================= //========= TARGET PICTURE name and vertexes SCR_PNT target_pos(0,0); // CONSTRACTOR default 0,0 pictJarget=sign_storage_rgb(argv[1 ],vc ); sign_present_RGB(pict * target, target_pos); //========= SCR_PNT StartPnt(0,0),EndPnt(pictJarget.s_cols-1 ,0); short Slope, Start, Stop; GOOD_DIR_LINE LocalMax[51]; //DEBUG // GRAPHJDUT(O); // LOOP over SLOPE for(Slope=MinSlope;Slope<=MaxSlope;Slope+=SlopeStep) { _settextposition( vcnumtextrows-3,0); printf("Sloρe %d", Slope); Start= max(0,-Slope); Stop= min(pictJarget.s_rows,pictJarget.s__rows-Slope); // LINE Calculation for (EndPnt.r=(StartPnt.r=Start)+Slope; StartPnt.r<Stop;StartPnt.r++,EndPnt.r++) { Lines[StartPnt.r]= GOOD_DIR_LINE::GOOD_DIR_LINE(StartPnt,EndPnt); 15\ AverageForLines[StartPnt.r]=LineMoments(pictJarget,Lines[StartPnt.r],MAP) } // Line Estimation short StartRow.QO.QUp.QDown; for (StartRow=Start;StartRow<Stop- DetectorWidthP I us; StartRow++) Lines[StartRow].Qual=Quality(AverageForLines+StartRow); //DEBUG #ifdef DBGO _clearscreen( _GCLEARSCREEN ); sign_present_RGB(pictJarget,target_pos); for (StartRow=Start; StartRow<Stoρ-DetectorWidthPlus; StartRow++) { _moveto(0, StartRow ); Jineto(10,StartRow+Slope+1 ); _moveto(255, StartRow+Slope+1 ); Jineto(255+(short)(Lines[StartRow].Qual * 0.5),StartRow+Sloρe+1); _settextposition( vcnumtextrows-2,0); __outtext( clean ); _settextposition( vcnumtextrows-2,0); sprintf(mesε,"Quality= %6g ",Lines[StartRow].Qual ); _outtext( mess);*/ } getch(); #endif // Line Selection for (QUp=0,StartRow=__max(0,-Slope); StartRow<Stop; StartRow++) { Q0=Lines[StartRow].Qual; QDown=(StartRow!=Stop-1)?Lines[StartRow].Qual:0; if((Q0>=QDown)&&(Q0>=QUp)) {LocalMax[50]=Lines[StartRow]; //including in consideration qsort((void*)LocalMax,51 ,sizeof(GOOD_DIR LINE ), compare_GOOD_DIR LINE); } QUp=Q0; } }// End Slope LOOP CString ProName(argv[1]); ProName+=".pln"; Writeϋnes(LocalMax,51 , (const char * )ProName); 153, // line grouping PT st_main,end_main,st_scnd,end_scnd; for(i=0;i<51;i++j if(LocalMax[i].Qual>0) {st__main=LocalMax[i].Start_p(); end_main=LocalMax[i].End_p(); for(j=i+1;j<51;j++) if(LocalMax[j].Qual>0) {st_scnd=LocalMaxQ].Start_p(); end_scnd=LocalMax[j]. End_p(); if((fabs(st_main.v-st_scnd.v)<DistanceThresh)|| qsort((void * )LocalMax,51 ,sizeof(GOOD_ iRJJNE), compare_GOOD_DIR_LINE); ProName=argv[1]; ProName+=".stp"; WriteLines(LocalMax,51 , (const char *)ProName); ProName=argv[1]; ProName+=".pn2"; WritePears(LocalMax,51 , (const char * )ProName, MaxStripNumber); GRAPH_OUT(); ρictJarget.free_PCT(); return(O); } // int get number_plines() // INITIALISATION GRAPHICMODE, GET SCALE { GRAPH_OUT(); cout « " MinSlope -20, MaxSlope 20, SlopeStep2 DistanceThresh 10 MAP \n"; cout « " NTSC 0 ColorPlanl 1 New_plan 2 RGB 3 LUMIN THR 4 IHS 5 \n"; cin »MinSlope» MaxSlope»SlopeStep»DistanceThresh»MAP; // ================ GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) GRAPH_OUT(-1 ); //================= return 1 ; } II /*mi ><_<___ -_-___«<-»*»»- int get_ umber_plinesJ(FILE * f) // INITIALISATION GRAPHICMODE, GET SCALE { fscanf(f," % * [ Λ \n]s "); fscanf(f," %d %d %d %d %d",&MinSlope,&MaxSlope,&SlopeStep,&DistanceThresh, &MAP); // Threshold for histogramme Number Of Points // for CorrThresh return 1 ; } //===================INTRODUCTION int lntroduction(int arg, char *a) { int FLG F=0; FILE *datainf; short n=0; if((arg != 2) && (arg !=3)) { printf(" target-file \n"); FLG_F=0; return(1 ); } else if(arg ==3) {FLG_F=1; if(!(datainf=fopen(a,"r"))) return 0; } if(FLG_F) {get_number_plinesj(dataiπf); // GET SCALE AND PARAMETERS fclose (datainf); } else get_number_plines(); return 0; } //========================================================= void WriteLines(GOOD DIR LINE *L,short MaxN, const char *name) { LineC.open(name,ios::out || ios::trunc); if(LineC.fail()) {LineC.clear(O); cout « "CAN NOT OPEN StripCollection"; GRAPH_OUT(-1); } LineC«" # \t st_X \t st_Y \t end_X \t end_y \t Value\n"; // OUTPUT all 51 line 15-1 short i; PT st, end; for(i=0;i<MaxN;i++) if((L+i)->Quai>0) {st=(L+i)->Start_p();end=(L+i)->End_p(); LineC« i«" \t"« (short)st.u«" \t"«(short)st.v+2« " \t"« end.u«" \t"« end.v+2« " \t"«(L+i)->Qual«'Λn"; I LineC.closeO; } / ======================================================== void WritePears(GOOD_DIR_LINE * L,short MaxN, const char * name,short PMax) { LineC.open(name,ios::out||ios::trunc); if(LineC.fail()) {LineC.cleartO); cout « "CAN NOT OPEN StripCol lection"; GRAPH_OUT(-1); } LineC«" Strip Collection \n"; // OUTPUT 16 pears short i,n=0,j; PT st,end,st2,end2; for(i=0;i<MaxN-1 ;i++) if((L+i)->Qual>0) {st=(L+i)->Start_p();end=(L+i)->End_ρ(); forG=i+1;(n<PMax) && G<MaxN);j++) if((L+j)->Qual>0) {n++; LineC« (short)st.u«" \t"« (short)st.v+2«" \t"« end.u«" \t"« end.v+2«'\n'; st2=(L+j)->Start_p();end2=(L+j)->End_p(); LineC« (short)st2.u«" \t"« (short)st2.v+2«" \t"« end2.u«" \t"« end2.v+2«'\n'; } } LineC.closeO; } //===========- ORIGIN = PWB ORIGIN_VER = 2.0 PROJ = LN_DEC2 PROJFILE = LN_DEC2.mak BUILDDIR = obj DEBUG = 1 BRFLAGS = /o obj\$(PROJ).bsc BSCMAKE = bscmake SBRPACK = sbrpack NMAKEBSC1 = set NMAKEBSC2 = nmake BROWSE = 1 CC = cl CFLAGS G = /W2 /BATCH /FR$ * sbr/Zn CFLAGS D = /f /Zi /0d CFLAGS R = /f- /Ot/0i /0l /Oe /Og /Gs CXX = ci CXXFLAGS_G = /AL W4 /G2 /D DOS /BATCH /FR$ * .sbr /Zn CXXFLAGS_D = li- /Od /FPi87 /Zi /DMICI /DSINGLE WIN /DJDEBUG CXXFLAGS_R = /f- /Ot /Ol /Og /Oe /Oi /FPiδ7 /Gs /DMICI /DSINGLE WIN MAPFILE_D = NUL MAPFILE R = NUL LFLAGS " G = /NOI /STACK:32000 /BATCH /ONERROR:NOEXE LFLAGS D = /CO /FAR/PACKC LFLAGS R = /EXE /FAR7PACKC LINKER = link ILINK = ilink LRF = echo > NUL ILFLAGS = /a /e LLIBS_R = LAFXCR LLIBS_D = LAFXCRD LLIBS_G = graphics CVFLAGS = /25 /S RUNFLAGS = \ilya\pnewline\tst\t0234e ln_dec.ini FILES = .ΛLIBWICALLOC.CPP ..\LIB\PROJCTN7.CPP ..\LIB\PIC_M7.CPP\ ..\LIB\RES_MCH7.CPP ..\LIB\L TRN7.CPP LN_TPL1.CPP LN DEC2.CPP OB " jS = objWICALLOC.obj obj\PROJCTN7.obj obj\PIC_M7.obj obj\RES_MCH7.obj\ obj\L_TRN7.obj objΛLN TPLLobj obj\LN_DEC2.obj SBRS = objWICALLOC.sbr obj\PROJCTN7.sbr obj\PIC_M7.sbr obj\RES_MCH7.sbr\ obj\L_TRN7.sbr obj\LN_TPL1.sbr obj\LN_DEC2.sbr all: obj\$(PROJ).exe .SUFFIXES: I5L .SUFFIXES: .SUFFIXES: .obj .sbr pp objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsρ /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch UF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « lELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « IENDIF obj\PROJCTN7.obj : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDBiostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDBistream.h C:\C700\INCLUDBostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /Focbj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « 1ELSE @$(CXX) @«cbj $(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Focbj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « /5T IENDIF obj\PROJCTN7.sbr : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PROJCTN7.sbr ..\LIB\PR0JCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « IENDIF obj\PIC_M7.obj : ..\LIB\PIC_M7.CPP C:\C700\INCLUDBstdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\lNCLUDBio.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float.h C:\C700\INCLUDE\malloch ..\LIB\phdr.h\ .ΛLIB icalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « IENDIF objΛPIC M7.sbr : ..\LIB\PIC_M7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\stnng.h\ C:\C700\INCLUDE\float.h C:\C700.INCLUDE\malloc.h ..\LIB\phdr.h\ .ΛLIB icalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « IENDIF objΛRES MCH7.obj : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ c7\C700\INCLUDE\vmemory.h ..\LIB\pic mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projc r-7.h CΛC700\INCLUDBmat .h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IENDIF objΛRES MCH7.sbr : ..\L1B\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projctn7.h C:\C700\INCLUDEΞ\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsρ /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « 1ENDIF obj\L_TRN7.obj : ..\LIB\L_TRN7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\malloc.h .ΛLIBWicalloc.h ..\LIB\linJrn7.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\pic_mch7.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\graph.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp is /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\L_TRN7.obj ..\LIB\L_TRN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\L_TRN7.obj ..\LIB\L_TRN7.CPP « IENDIF objΛL TRN7.sbr : ..\LIB\L TRN7.CPP C:\C700\INCLUDE\stdlib.h\ " C:\C700\INCLUDBstdio.h C:\C700\INCLUDE\conio.h\ C:\C700\INCLUDE\malloc.h .ΛLIB icalloch ..\LIB\linJrn7.h\ C:\C700\INCLUDBvmemory.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\pic_mch7.h C:\C700\INCLUDE\math.h C:\C700\INCLUDE\graρh.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\L_TRN7.sbr ..\LIB\L_TRN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\L_TRN7.sbr ..\UB\L_TRN7.CPP « IENDIF C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloch\ C:\C700\INCLUDE\float.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\ctype.h match5.h\ ..\LIB\pic_mch7.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\linJrn7.h C:\C700\INCLUDBvmemory.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\LN_TPL1.obj LN_TPL1.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\LN_TPL1.obj LN_TPL1.CPP « lENDIF IW> C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloch\ C:\C700\INCLUDE\float.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\ctype.h match5.h\ .. \LIB\pic_mch7.h ..\LIB\projctn7.h ..\LIB\res_mch7.h\ ..\LIB\linJrn7.h C:\C700\INCLUDE\vmemory.h C:\C700\INCLUDE\math.h IIF $(DEBUG) @$(CXX) @«obj $(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\LN_TPL1.sbr LNJTPL1.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\LN_TPL1.sbr LN TPL1.CPP « IENDIF objΛLN DEC2.obj : LN DEC2.CPP C:\C700\INCLUDE\stdlib.h C:\C7θ " θ\INCLUDE\conio.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDBstring.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\fIoat.h\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUDE\fstream.h\ C:\C700\INCLUDE time.h matchδ.h ..\LIB\vicalloch\ C:\C700\INCLUDBctype.h C:\C700\MFC\INCLUDBafx nl\ C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LlB\res mch7.h ..\LIB\linJrn7.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\LN_DEC2.obj LN_DEC2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\LN_DEC2.obj LN_DEC2.CPP « IENDIF C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\fioath\ C:\C700\MFC\INCLUDE\afx.h C:\C700\INCLUDE\fstream.h\ tb\ C:\C700\INCLUDE\time.h matchδ.h ..\LIB\vicalloch\ C:\C700\INCLUDE\ctype.h C:\C700\MFC\INCLUDE\afx.inl\ C:\C700\INCLUDBiostream.h ..\LlB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h ..\LIB\linJrn7.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDBostream.h\ C:\C700\INCLUDE\math.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\LN_DEC2.sbr LN_DEC2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\LN_DEC2.sbr LN_DEC2.CPP « IENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) - $(PROJFILE) obj\$(PROJ).bsc !IF $(DEBUG) $(LRF) @«obj\$(PROJ).lrf $(RT OBJS: = + Λ ) $(OBJS: = +* ) $@ $(MAPFILE_D) $(LIBS: = + ) + $(LLIBS_G: = + ) + $(LLIBS_D: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_D); « ELSE $(LRF) @«obj\$(PROJ).lrf $(RT_OBJS: = + Λ ) $(OBJS: = + Λ ) $@ . bS. $(MAPFILE_R) $(LIBS: = + Λ ) + $(LLIBS G: = + Λ ) + $(LLIBS_R: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « IENDIF $(LINKER) @obj\$(PROJ).lrf .cpp.obj : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoS@ $< « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoS@ $< « ENDIF .cpp.sbr : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRS@ $< « ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FR$@ $< « ENDIF run: obj\$(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV $(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) /63 #ifndef MATCH #defιne MATCH #include "projctn7.h" #include "pic_mch7.h" #include "res_mch7.h" #include "Iin rn7.h" //#include "tem_plt7.h" #define NAME_LENGTH 40 #defιne GRAPHMODE _VRES256COLOR //COLOR_RGB INTER_pix_color_rgb(PCT p1, PT PT_now); #endif // STRIP SELECTION // Module gets a strips after line detection (module plines // and selects two lines with a maximumm informational // contents (frequency approach). // COMMAND STRING // // Ins corr <TARGET_name> [CommandFile] // // <TARGET_name> File name of FRAME without extention // ^ [CommandFile] Optional ASCI file with a run time parameters. // // INPUT //=======ATTENTION // LN_DEC2 used .ρn2 files - output PLNEW modules // RGB files of frame (field) and corresponding .SGN files created by // module PLINE. // RUN TIME parameters: // // <four number> -shift of strips vertexes relative to original> // <V HJow H_up Hight Width> -Five integer: // V - The highest vertical harmonic; // HJow, H_up - The lowest and highest horisontal harmonics; // Hight, Width - Hight and Width of windowfor analyses. // <Gap HalfScrWeight PosWeight> - Integer and two float <1 : // Gap . - range unsensetivites to screen position; // HalfScrWeight - Additional weght if an upper line is // in upper half of screen // PosWeight - Additional weght if miuddle line belower // then middle line of another line. //SEE ALSO FILE "LN_DEC.ini" // OUTPUT // TARGET_name.SG2 - Strips selected; // LINEDET.002 - result collection for analyses, // includes keyboard information to analyse. //=======ATTENTION // LN_DEC2 OUTPUT // TARGET_r.ame.SG2 - Strips selected; // LINEDET.002 - result collection for analyses, // includes keyboard information to analyse. #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <graph.h> #include <float.H> #include <afx.h> #include <fstream.h> #include <time.h> lbs #include "matchδ.h" #include "vicalloc.h" #include <ctype.h> short PRESENTJHIGHT; short GAP=δ; double HalfScrWeight=0.1, PosWeight=0.1; short TAGJiight; struβt videoconfig vc; SCR_PNT vrtjarget[4]; FILE *datres; double sh[4]={0,0,0,0}; double GAMMA=1.0,CORR_THRESH-0,Thresh_mdl=0; short VOITING=0,MAP=0; char f_name[40]="J', FILE name[40]=" ". FRAME Name[40]="J\ STRING_name[40]="J', SIGN_name[40]="J'; PCT pictjarget, target_map; short win_hight,wiπjenth; short HOR_HARMJ,HOR_HARM_h,VERT_HARMJ ; int cdecl compare_aιτay_elem ( const void *elem1, const void *elem2 ); int Picturelnf( const char * name,SCR_PNT *vertexes, short n); //int picturejnf_num_new(char *name,SCR_PNT * vertexes, short n); void get_shiftJ(FILE * f,double * sh); // INITIALISATION GRAPHICMODE, GET SCALE void get_shift(double * sh); // INITIALISATION GRAPHICMODE, GET SCALE int get_number_3(); int get_number_3J(FILE * f); double GlobalWinCalc(PCT target_map, SCR PNT win_size, short winpos); //========================================================== ofstream LineC; //============ OpenStripCollection void OpenStripCol(const char * name) { LineC.open(name,ios::out|ios::app|ios::out|ios::nocreate); if(LineC.fail()) {LineC.clear(O); LineC. open(name,ios::out|ios::app|ios::out|ios::noreplace); if(LineC.failO) {LineC.clear(O); cout « "CAN NOT OPEN StripCollection"; GRAPH_OUT(-1); } else LineC«"StripAnalysCollection \n"; } 16b LineC«"Name #1\tVERT_HARM I \t"« " HOR_HARM I tt HOR HARM h \t WindowLength\n"; } //============================================ int main(int argc.char * argvfl) { char *p,mess[128],cleanQ-" "; SCR PNT line_vrt[20][4]; int FLG_F=0; FILE *datainf; short n=0; SCR PNT t_pos; if((argc != 2) && (argc !=3)) { printf(" target-file \n"); FLG_F=0; retum(1 ); } else if(argc ==3) {FLG_F=1; if(!(datainf=fopen(argv[2],"r"))) return 0; } ιf(FLG F) {get_shiftj(datainf,sh); // GET SCALE get_number_3J(datainf); } else {get_shift(sh); // GEΞT SCALE get number_3(); } // PROTOCOL OUTPUT CString ProName("linedet.002"); strcpy(f_ ame, argv[1 ]); OpenStripCol((coπst char *)ProName); LineC«f name«" \t" «VERT_HARM 1«" \t"« HOR_HARMJ«" \t" «HOR HARM_h«" \t"<^win leπth«Λn'; LineC«"GAP="« GAP« " \tHalfScrWeight="«HalfSCTWeight« " PosWeight- "«PosWeight« Λn'; LineC«" Line # \t Hight \t Value \t Comm \n"; // ================ GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) GRAPH_OUT(-1 ); //================= //========= TARGET PICTURE name and vertexes SCR_PNT target_pos; // CONSTRACTOR default 0,0 pict Jarget=sign_storage_rgb(argv[1 ], vc ); //========= PROTOTYPE~initialisation short j,k; 161 double res[20]; for(j=0;j<20;res[j++]=0.0); CString FName(' ',80); FName=argv[1]; FName+=".pn2"; while(Picturelnf((const char*)FName,vrt target, n++)) { SCR.PNT vrt[4]; match_vertex( vrt arget); for(j=0;j<4;j++) { vrtQ]. c=vrt argetQ]- c; k=((j%2)?j-1:j+1); if (fabs(sh[j])<1) {vrtϋ].r=(shQ]?(short)((vrtJargetϋ].r-vrtJarget[k].r)*sh[j])+ vrt arget[j].rvrt target[j].r); } else vrtQ]. r=vrt _target[j]. r+sh[j]; } #defιne CALC_HIGHT 16 TAG_hight=(short)(vrt[2].r-vrt[3].r+vrt[1].r-vrt[0].r+2)*0.5; if(TAG_hight<10) continue; target_map=linearJransform_cont(pictJarget, vrt, CALC_HIGHT ); if ( !target_map. s_cols) {printfCTOO NARROW LINES");continue;} match_vertex( vrt); PRESENT_HIGHT=16; _clearscreen(j3CLEARSCREEN); target_pos.c=10; target_pos.r=10; sign_preseπt_RGB( target map,target_pos); //================================== SCR_PNT win_size(128,4); short winpos; win_size.r=(win_hight>0)?__min(win_hight,CALC_HIGHT):CALC_HIGHT; win_size.c=(winjenth>0)? min(winJenth,target__map.s_cols) :target_map. s_cols; winpos=(CALC_HIGHT-win__size.r)/2; const double scale=(double)PRESENT_HIGHT/CALC_HIGHT; // RESULTS AND VERTEXES res[n-1]= GlobalWinCalc(target_map,win_size, winpos); for (j=0;j<4;j++) line_ rt[n-1]G]=vrt[j]; target_map.free_PCT(); //================================================= /6g LineC« n-1«" \t"« TAG_hight«" \t"« res[n-1]«" \t"; //LineC«" Line # \t Hight \t Value \t Comm_1 \t COMM_2 \n"; sprintf(mess,"File Name "); _settextposition( vcnumtextrows-2,0); _puttext( clean ); _settextposition( vc.numtextrows-2,0); _outtext( mess ); p=mess; while(!isspace( (int)( * p++=(char)getche()) )); *(-p)='\0'; LineC «mess«'Λt\n"; //======================================================== } // DECISION MAKING short i,nl[5], upJn[5],topJn[5]; short best=0,scnd-0; double * nmb[20],weight[5]={0,0,0,0,0}; for(i=0;i<20;i++) nmb[i]=res+i; qsort((void * )nmb,20,sizeof(double * ),compare_array_elem ); for(i=0;i<5;i++) {if(!(*nmb[i])) break; nl[i]=nmb[i]-res; upjn[i]=line_vrt[nl[i]][3].r+line_vrt[nl[i]][0].r; topJn[i]=line_vrt[nl[i]]R].r+line_vrt[nl[i]][2].r; weight[i]=*nmb[i]; } if(weight[0]) {if((up Jn[1 ]+top Jn[1 ])>(up Jn[0]+topJn[0]-GAP)) weight[1 ] * =(1.0+PosWeight); if(upjn[1 ]>pict Jarget.s_rows) weight[1 ] * =(1.0+HalfScrWeight); if(up ln[0]>pict target.s_rows) weight[0] * =(1.0+HalfScrWeight); scnd=(best=(weight[0]<weight[1])?1 :0)?0:1 ; // DESCISION OUTPUT target_pos.c=10; target_pos.r=10; _clearscreen(J3CLEARSCREEN); target_map=linear ransform_cont(pict arget, line_vrt[nl[best]], 16 ); sign_present_RGB( target_map,target_pos); target_map.free_PCT(); if(weight[scnd]) { target_pos.r+=20; target_map=linearJransform_cont(pict Jarget, line_vrt[nl[scnd]],16 ); sign_present_RGB( target_map,target_pos); /6Q target_map.free_PCT(); } sρrintf(mess, "Result 1_res= %6g w= %6g 2_res=%6f W=%6f \0", *nmb[best],weight[best],*nmb[scnd],weight[scnd]); char Sn1[20]; _settextposition( vc.numtextrows-2,1 ); _puttext( clean ); _settextposition( vcnumtextrows-2,0); _outtext( mess ); p=Sn1; while(!isspace( (int)(*p++=(char)getche()) )); *(-P)='\O'; strcat(mess,Sn1); LineC« mess«'\n'; LineC.closeO; //picture presentation _clearscreen(J3CLEARSCREEN); target_pos.c=0; target_pos.r=0; target_map=linearJransform_cont(pict Jarget, line_vrt[nl[best]],16 ); sign_present_,RGB( pictJarget,target_pos); _setcolor( color_num(240,240,240)); _moveto(line__vrt[nl[best]][3].c,line_vrt[nl[best]][3].r); jineto(line_vrt[nl[best]][0].c,line_vrt[nl[best]][0].r); _moveto(line_vrt[nl[best]][2].c,line_vrt[nl[best]][2].r); Jineto(line_vrt[nl[best]][1 ].c,Iine_vrt[nl[best]][1 ].r); getch(); if(weight[scnd]) { _setcolor( color_num(240,240,0)); _moveto(line_vrt[nl[scnd]][3].c,line_vrt[nl[scnd]][3].r); jineto(line_vrt[nl[scnd]][0].c,line_vrt[nl[scnd]][0].r); _moveto(Iine_vrt[nl[scnd]][2].c,line_vrt[nl[scnd]][2].r); Jineto(line_vrt[nl[scnd]][1].c,line_vrt[nl[scnd]][1].r); getc O; } strcat(strcpy(f_name,argv[1]),".sg2"); LineC.open(f_name,ios::out); LineC«"Afte7 Str Selection\n"; LineC«argv[1 ]«" "«Sn1 «" \t" «Sn1 «'\n"; for(j=0;j<4;j++) LineC«line_vrt[nl[best]]0].c«" \t"«line_vrt[nl[best]]u].r« , \n'; if(weight[scnd]) forϋ=0;j<4;j++) LineC«line_vrt[nl[scnd]][j].c«" \t"«line_vrt[nl[scnd]]0].r« , \n , ; LineC.closeO; // END DECISION mo } else { LineC.open(f_name,ios::out); LineC«"After Str Selection^"; LineC«argv[1]«" "«" \t \n": LineC.closeO; cout «" Lines not proposed"; } GRAPH_OUT(); pictJarget.free_PCT(); target_map.free_PCT(); fclose(datres); retum(O); } //= int cdecl compare_array_elem ( const void *elem1, const void *elem2 ) {int i; double a; a=* * (double ** )elem1- ** (double * * )elem2; i=(a?((a<0)?1:-1):0); return i; } // void get_shiftJ(FILE * f,double * sh) // INITIALISATION GRAPHICMODE, GET SCALE { fscanf(f," %lf %lf %lf %lf ,sh,sh+1 ,sh+2,sh+3); } // void get_shift(double *sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; cout« "vertexes shift over rows ( top_right, bottom_right, bottomjeft, toρ_left %\n"; for (i=0;i<4; i++) cin»sh[i]; } //========================================================== int get number 3() { GRAPH_OUT(); til cout « " VERT_HARM<16 HOR_HARM_start<16 HOR_HARM_stop,win_hight winjenth"; cin »VERT_HARM_1»H0R_HARMJ»H0R_HARM_h»win_hight»winJent h; cout«" GAP HalfScrWeight % PosWeight % "; cin»GAP»HaifScrWeight»PosWeight; HalfScrWeight/=100.0; PosWeight/=100.0; // ================ GRAPHICS START if(GRAPHICS START(&vc,GRAPHMODE)) GRAPH OUT(-1); //================= return 0; } int get number_3J(FlLE * f) { fscarif(f," %d %d %d %d %d",&VERT_HARM 1, &HOR_HARM l.&HORJHARM h,&win_hight,&win lenth); fscanf(f," %d %lf %lf \&GAP f &HalfScrWeight,&PosWeight); HalfScrWeight/=100.0; PosWeight =100.0; return 1 ; } //================================ int Picturelnf(const char * rame,SCR_PNT * vertexes, short n) {int i,j; ifstream datfp; char new_str[80]; int r,FLG=0; datfp.open(name,ios::in); if(datfp.fail()) {datfp. clear(O); cout « "CAN NOT OPEN InfFiie "« name«'Λn"; GRAPH_OUT(-1); } datfp.getline(new_str,80); forO=0;j<n+1;j++) for(i=0;i<4;i++) {datfp»(vertexes+i)->o>(vertexes+i)->r; if(datfp.eof()) {datfp.close (); return 0;} } datfp.close (); return 1 ; } //========================================================== πa #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <malloc.h> #include <float.h> #include <graph.h> #include <string.h> #include <ctype.h> #include "match5.h" #include "pic mch7.h" #dβfine MAXJ_INE 1024 extern short TAGJiight; extern struct _videoconfig vc; extern, char f_name[40],FILE_name[40], FRAME Name[40], STRING_name[40], SIGN_name[40]; typedef struct {double md[3],var[3];} AVERAGE VEC; //=====================================================—-— extern short HOR_HARMJ; extern short HOR_HARM_h; extern short VERT_HARM_1 ; II double calcul_power(PCT win.short x_scaie, double *vr) {const short VERT_HARM=VERT_HARM_1 * 2, HOR_HARM=HOR_HARM_h*2, HOR_HARM_s=HOR_HARMJ?HOR_HARMJ * 2-1:HOR_HARMJ; const short THR=16; double sum[19][19]; COLOR_RGB col; double pow=0,mid=0; short d ; long l_now; long n; short hJ,vJ,x,y,h,v,half_x,half_y,quot_x,quot_y; n=win.s_cols * win.s_rows; half_y=win.s_rows»1 ; quot_y=win. s_rows»2; //! !!!! !! !!!!!!!!! ! !! ! ! ! !!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!! half_x=x_scale»1 ; quot_x=x_scale»2; // half_x=win.s_rows»1; // quot_x=win.s_rows»2; // half_x=win.s_cols»1 ; // quot_x=win.s_cols»2; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! H3 for(h=0;h<HOR_HARM+1 ;h++) for(v=0;v<VERT_HARM+1 ;v++) sum[v][h]=0; for(y=0;y<win.s_rows:y++) for(x=0;x<win.s_cols;x++) {col=win.get_pixel(y,x); l_now=col.r+col.b+col.g; l_now=(l_now>THR)?l_now.O; mid+=_now; pow+=l_now * l_now; for(v=0;(v<VERT_HARM+1 ) &&(((v+1 )»1 )<=quot_y);v++) { v J=y*((v+1 )»1 ); // HARMONIC # =(v+1 )»1 vj=(vj+(v & 0x0001 ? quot_y:0))/half_ ; vj &= 0x0001 ; //1 if y_pαs in 2nd half d= vJ?l_now:-l_now; for(h=HOR_HARM s;(h<HOR_HARM+1 )&&(((h+1 )»1 )<=quot_x);h++) { hj=x * ((h+1)»1); h t=(h t+(h & 0x0001 ?quot_x:0))/half_x; hj &= 0x0001; - sum[v][h]+= hj?d:-c1; } } } double sO.dd; for(sO=h=0;h<HOR_HARM+1 ;h++) for(v=0;v<VERT_HARM+1 ;v++) if(h||v) sO+=(double) sum[v][h] * sum[v][h]; sO/=n; *vr=(dd=(pow-mid*mid/n))?sO/dd:0; //return add_out; return (s0/(n * 100.0)); } _ double GlobalWinCalc(PCT target_map, SCR PNT win__size, short winpos) { double centr_pow; double pow_now; long n Jr=0; double mid_pow=0; double rev r; PCT win(win_size.c,win_size.r); SCR_PNT stj,st_win; i t. st_win.r=winpos; for (st win.c=0;st_win.c<target_map.s_cols-win_size.c+1 ;st_win.c++) { ' win.loadJemplate(target_map,st_win); r(win,target_map. s_rows, &centr_pow); win.free_PCT(); return mid_pow; } 115 ORIGIN = PWB ORIGIN ER = 2.0 PROJ = LNS_CORR PROJFILE = LNS_C0RR.MAK BUILDDIR = obj DEBUG = 0 BRFLAGS = lo obj\$(PROJ).bsc BSCMAKE = bscmake SBRPACK = sbrpack NMAKEBSC1 = set NMAKEBSC2 = nmake BROWSE = 1 CC = cl CFLAGS G = /W2 /BATCH /FR$*.sbr/Zn CFLAGS D = /f /Zi /Od CFLAGS_R = /f- /Ot /Oi /OI /Oe /Og /Gs CXX = cl CXXFLAGS G = /AL /W4 /G2 /D_DOS /BATCH /FR$*.sbr /Zn CXXFLAGS D = /f- /Od /FPiδ7 /Zi /DMICI /DSINGLE WIN CXXFLAGSJ = /f- /Ot /Ol /Og /Oe /Oi /FPi67 /Gs /DMICI /DSINGLEJ/VIN MAPFILE_D = NUL MAPFILE_R = NUL LFLAGS G = /NOI /STACK32000 /BATCH /ONERROR:NOEXE LFLAGS D = /CO /FAR/PACKC LFLAGS_R = /EXE /FAR /PACKC LINKER = link ILINK = ilink LRF = echo > NUL ILFLAGS = /a /e LLIBS G = graphics lafxcr CVFLAGS = /25 /S RUNFLAGS = ..\win4\S160_0 ..\win4\S160_ autol FILES = LNS_CORR.CPP ..\LIBWICALLOC.CPP ..\LIB\PROJCTN7.CPP\ ..\LIB\PIC_M7.CPP ..\LIB\RES MCH7.CPP COR_FNC.CPP COR WIN.CPP OBJS " = obj\LNS_CORR.obj objWICALLOC.obj obj\PROJCTN7.obj objΛPIC M7.obj\ obj\RES_MCH7.obj objΛCOR FNC.obj objΛCOR WIN.obj SBRS = obj\LNS_CORR.sbr objWICALLOC.sbr obj\PROJCTN7.sbr objΛPIC M7.sbr\ obj\RES_MCH7.sbr obj\COR_FNC.sbr objΛCORJ/VIN.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp lib obj\LNS_CORR.obj : LNS_CORR.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\float. H C:\C700\INCLUDE\io.h C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\iostream.h\ C:\C700\MFC\INCLUDE\afx.h LNS_CORR.h cor_win.h c:\ilya\lib\vicalloc.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\MFC\INCLUDE\afx.inl ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\linjrn7.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsρ /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\LNS_CORR.obj LNS_CORR.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\LNS_CORR.obj LNS_CORR.CPP « ENDIF obj\LNS_CORR.sbr : LNS CORR.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDBconio.h C:\C700\INCLUDBstdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDBfloatH C:\C700\INCLUDBio.h C:\C700\INCLUDE\time.h\ C:\C700\INCLUDE\ctype.h C:\C700\INCLUDE\iostream.h\ C:\C700\MFC\INCLUDE\afx.h LNS_CORR.h cor_win.h c:\ilya\lib\vicalloch\ C:\C700\INCLUDBios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDBistream.h C:\C700\INCLUDBostream.h\ C:\C700\MFC\INCLUDBafiunl ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\lin_trn7.h C:\C700\INCLUDBvmemory.h\ C:\C700\INCLUDBmath.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\LNS_CORR.sbr LNS_CORR.CPP « IELSE @$(CXX) @«objΛ$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\LNS_CORR.sbr LNS_CORR.CPP « NDIF objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloc.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « ENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobjWICALLOC.Sbr .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « ENDIF obj\PROJCTN7.obj : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDBstdlib.h C:\C700\INCLUDBiostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDBstreamb.h\ C:\C700\INCLUDBistream.h C:\C700\INCLUDBostream.h\ C:\C700\INCLUDBmath.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Focbj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « ELSE @$(CXX) @«cbj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Focbj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « ENDIF ns obj\PROJCTN7.sbr : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«cbj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFL_AGS_R) /FRobj\PROJCTN7.sbr ..\LIB\PR0JCTN7.CPP « ENDIF obj\PIC_M7.obj : ..\LIB\PIC_M7.CPP C:\C700\INCLUDBstdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE math.h\ C:\C700\INCLUDBio.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\fIoat.H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ c:\ilya\lib\vicalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « ENDIF objΛPIC M7.sbr : ..\LIB\PIC M7.CPP C:\C700\INCLUDBstdlib.h\ C:\C700\INCLUDE\s7dio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\floatH C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ c:\ilya\Iib\vicalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp πq /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP << ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « ENDIF obj\RES_MCH7.obj : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\RES_MCH7.obj ..\L1B\RES_MCH7.CPP « IENDIF objΛRES MCH7.sbr : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\graρh.h ..\LIB\projctn7.h C:\C700\INCLUDEΞ\math.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\RES_MCH7.sbr ..\LIBVRES_MCH7.CPP « ENDIF objΛCOR FNC.obj : COR_FNC.CPP C:\C700\INCLUDE\stdio.h C:\C700 NCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDBfloat.H\ C:\C700\INCLUDE\graph.h corjnc.h ..\LIB\pic_mch7.h ..\LIB\res_mch7.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp 110 /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\COR_FNC.obj COR_FNC.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\COR_FNC.obj COR_FNC.CPP « ENDIF obj\COR_FNC.sbr : COR_FNC.CPP C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\float. H\ C:\C700\INCLUDE\graph.h corjnc.h ..\LIB\pic_mch7.h ..\LIB\res mch7.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\COR_FNC.sbr COR_FNC.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\COR_FNC.sbr COR_FNC.CPP « ENDIF objΛCOR WIN.obj : COR WIN.CPP C:\C700\INCLUDBvmemory.h\ C:\C700\INCLUDE\stdio.h C.\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h\ IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsρ /c $(CXXFLAGS G) $(CXXFLAGS_D) /Foobj\COR_WIN.obj COR_WIN.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /FαobjΛCORJ/VIN.αbj COR_WIN.CPP « ENDIF obj\COR_WIN.sbr : COR_.WIN.CPP C:\C700\INCLUDBvmemory.h\ lt\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\conio.h C:\C700\INCLUDE\malloc.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\string.h LNS_CORR.h corjnc.h ..\LIB\projctn7.h\ ..\LIB\pic_mch7.h ..\LIB\res_mch7.h c:\ilya\lib\linjrn7.h\ C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\COR_WIN.sbr COR_WIN.CPP « ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRcbj\COR_WIN.sbr COR_WIN.CPP « ENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) -f $(PROJFILE) obj\$(PROJ).bsc IIF $(DEBUG) $(LRF) @«obj\$(PROJ).lrf $(RT_OBJS: = + Λ ) $(OBJS: - + ) $@ $(MAPFILE_D) $(LIBS: = +* ) + $(LLIBS G: = +* ) + $(LLlBS D: = +* ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGSJD); « ELSE $(LRF) @«obj\$(PROJ).lrf $(RT OBJS: * + Λ ) $(OBJS: = + Λ ) $@ $(MAPFlLE_R) $(LIBS: = + Λ ) + $(LLIBS_G: = + Λ ) + $(LLIBS_R: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « ENDIF * $(LINKER) @obj\$(PROJ).lrf .cpp.obj : !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Fo$@ $< « ELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Fo$@ $< « ENDIF .cpp.sbr : IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_ )7FRS@ $< « ELSE @$(CXX) @«obj\$(PROJ).rsρ /Zs $(CXXFLAGS G) . $(CXXFLAGS_R)7FR$@ $< « ENDIF run: obj\$(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV $(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) 1*3 // Module calculates correlation functions of PROTO_1 and set of // prototypes. Set of prototypes' names is defined by a MASK correspondes // to names generated by MAKEPRB and has next structure: // [path]&RRW_P.rgb // Where ■ optional name of directory; first letter of file name two digits corresponding to prototype's hight (RR= 16| 32 | 48 | 64) number corresponding to window number (see description, prototype Number // MASK includes ONLY [path]&RRW_ and programme will // calculate correlation functions for prototypes with P from 0 to // first not existing number. // COMMAND STRING // // lns_corr <PROTOJ_Name> <MASK> [CommandFile] // // <PROTO_1_Name> File name of PROTOTYPE without extention // <MASK> Mask for prototypes FileNames without extention and // Prototype's number. // [CommandFile] Optional ASCI file with a run time parameters. // // INPUT // RGB files of prototypes and corresponding .SGN files created by // module MAKEPRB. // RUN TIME parameters: // // 0 000 -shift for all cases have to be 0 // <CalorSpace> // We have used 1 - as worked only with a luminance // <Window width> // We have used 8 //SEE ALSO FILE "LNS CORR.INI" // OUTPUT // Correlation functions in PROTO LDBC file. #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <graph.h> #include <float.H> #include <io.h> #include <time.h> #include <ctype.h> #include <iostream.h> #include <afx.h> #include "LNS_CORR.h" #include "cor_win2.h" #include "vicalloch" char f name[40]="J',FILE_name[40]="JV FRAME_Name[40]="J', ARGV_1[30]="J\ STRING_name[40]="J', SIGN_name[40]="J',TAG name[9]-" ", double GAMMA=1.0,CORR_THRESH=0.0,Thresh_mdl=0.0; short MAP; short VOITING=3,TAG_hight; struct _videoconfig vc; FILE *datres; int FLG_WRIGHT=0; double sh[4]={0,0,0,0}; PCT pict target, pict_proto; FILE * out_rslt; int picturejnf(char * πame,SCR_PNT *vertexes); int picture inf_num(char *name,SCR PNT *vertexes,short n); int get_number(); // INITIALISATION GRAPHICMODE, GET SCALE int get_ umber_3(); // INITIALISATION GRAPHICMODE, GET SCALE void get shift J(FILE f.double * sh); // INITIALISATION GRAPHICMODE, GET SCALE void get shift(double * sh); // INITIALISATION GRAPHICMODE, GET SCALE int get number_3J(F!LE * f); // INITIALISATION GRAPHICMODE, GET SCALE int picturejnf_num_2(char * name,SCR_PNT * vertexes,short n.char *ext); int picturejnf_num_new(char *name,SCR_PNT * vertexes, short n); //φφφφφφφφφφ φφφφφφφφφφφφφφφφφφφφφφφφ ΦΦΦΦΦΦΦΦΦΦΦ φ φφ φ^fφ //φφψ ψ ψwwψψψψψψψφψ short PRESENT_HIGHT=32, CALCJHIGHT =32; FILE * INP.PROTOCOL; FILE *PROTOCOL; CString PROTOCOL NAME; CString PROTOCOL START; CString PROTO1_HEADER=CString::CString( tS5 "PROTO_File\tFRAME_Name\tSTRING_πame\tS_name\tSLength\tWinLengt h\tSPACE\n"); CString PROTO_TAG_HEADER=CString::CString( 'TAG_Fiie\tFRAME_ ame\tSTRING_name\tS_Name\tLegnth\tCOMM\n"); void init_protocol(char * name) {short FLG; FLG= access(PROTOCOL_NAME,0); 110 if exist PROTOCOL=fopen(PROTOCOL_NAME,"a"); if(FLG) fprintf(PROTOCOL."AUTO and CROSS correlation functions \n %s", PROTO1 HEADER); PROTOCOL_START=name; PROTOCOL_START+= * Λt"; } //========================================================== int openJnp_prot(char * name) {if(!(INP_PROTOCOL=fopen(name,Y'))) return 1; //split first str fscanf(INP_PROTOCOL,"%*[ Λ \n]s"); return 0; } ψφφφψφφφφφψφφψφφψψφψφψφφφψφφφφφφφφ //return file name without extwntion in "name" and TRUE 1 if file exist; int next_pict(char *name,char *mask,char *ext,int num) //if num=-2 initalisation; // -1 next // >0 adding this # to mask // NULL if notexist file with ".rgb" {static int now; char ful l_ηame[80]; strcpy(name,mask); if (num==-2)now=0; else if (num==-1 ) now++; else if (num<0) return 1 ; else now=num; Jtoa( now, name+strien(name), 10); strcat(strcpy(full_name,name),ext); //1 if file exist return(! access( full_name, 0 )); } //========================================================== /S #include <f stream. h> int ReadStrlnf(char * name,short * StD) {ifstream InpF; char a[80]; strcat(strcpy(a,name),".str"); short i; lnpF.open(a,ios::in|ios::nocreate); if(lnpF.fail()) {InpF.clear(O); return 1 ; } lnpF.getline(a,80,'\n'); InpF.getlineja.SO. n'); lnρF.getline(a,δO,'\n'); lnρF.getline(a,δO,'\n'); InpF.getlineia.δO.Λn'j; lnpF.getline(a,δO,'\n'); i=0; do { lnpF»StD[i++]; if (InpF.eofOH i>17) { StD[-i]=-1; break; } lnpF»StD[i++]; } while(1); InpF.closeO; return 0; } //= SCR PNT winsize; //==—==========; int main(int argc.char'argvQ) {int FLG_F=0, FLG_WRIGHT=0; FILE *datainf; short winstep, map_stnd; short n=0; SCR PNT t_pos; if((argc != 3) && (argc !=4)) { printf(" target-file protojile mask \n"); FLG_F=0; retum(1); } m else if(argc ==4) {FLG_F=1 ; if(!(datainf=fopen(argv[3],"r"))) return 0; } if(FLG F) {get_shiftj(datainf,sh); // GET SCALE get_number_3J(datainf); // GET SCALE } else {get_shift(sh); // GET SCALE 0 get_number 3(); } strcpy(ARGV 1 ,argv[1]); PROTOCOL ~NAME=argv[1]; PROTOCOL_NAME+=".dbc"; init_protocol(argv[1 ]); // ================ GRAPHICS START if(GRAPHICS_START(&vc,GRAPHMODE)) exit(-1 ); //========= TARGET PICTURE name and vertexes SCR_PNT target_pos; // CONSTRACTOR default 0,0 short StrDescr[17]; _splitpath( argv[1], drive, dir,TAG_name,ext ); pict Jarget=sign_storage gb(argv[1 ],vc ); if(ReadStrlnf(argv[1 ],StrDescr)) {printffSTR PROTO not exist"); GRAPH OUT(-1);retum -1; }; winsize. r=pict Jarget. sjrows; winstep=winsize.c; //"PROTO File\tFRAME Name STRING name\tS name\SLength\tWinLengt h\tSPACE\ή"); fprintf(PROTOCOL,"%s %δs\t%6s\t%12s\t%4d\t%4d\t%12s\n%s H . (const char * )PROTOCOL_START,FRAME_Name,STRING_name,SIGN_name, pictJarget.s_cols,winsize.c,SP[MAP], (const char * ) PROTO_TAG_HEADER); //========= PROTOTYPE LOOP OVER names char proto_name[NAME_LENGTH],buff[4]; SCR_PNT proto_pos.z; //loop over masks //return file name without extention in "name" and TRUE 1 if file exist short proto_number=0; //# 0; while( next_pict( proto_name,argv[2].".rgb", proto iumber)) { proto number=-1 ; //next; SCR_PNT pr_v[4]; // PROTO INFORMATION IN PROTOCOL pict_proto=sign_storage_rgb(proto_name,vc ); picturejnf_num_2(proto_name,pr_v,0,".str"); //only for SIGN_name // 'TAG_File\tFRAME_Name\tSTRING_name\tS_Name\tLegnth\n") fprintf(PROTOCOL," %12s\t %3s\t %6s\t %12s\t%4d\n", proto_name,FRAME_Name,STRING_name,SIGN_name,pict_proto.s_cols); TAG_hight=pict_proto.s rows; // TARGET PRESENTATION _clearscreen(_GCLEARSCREEN); proto_pos.c=target_pos.c=10; proto_pos.r=(target_pos.r=10)+pictJarget.s_rows+5; sign_present_RGB( pictJarget,target_pos); sign_present_RGB(pict_proto,proto_pos); //= corτ_win_proto(pictJarget, pict_proto, winsize, winstep,CORR_THRESH,StrDescr); pict_proto.free PCT(); } _displaycursor( J3CURSORON ); _setvideomode( _DEFAULTMODE ); pict target.free_PCT(); fclose(PROTOCOL); return(O); } // void get_shiftJ(FILE f.double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; for(i=0;i<4; i++) { fscanf(f,"%lf %lf\n",sh+i++,sh+i); } } // void get_shift(double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; cout« "vertexes shift over rows ( top ight, bottom_right, bottom_left, topjeft %\n"; for (i=0;i<4; i++) cin»sh[i]; } //======================================================- int get_number_3() // INITIALISATION GRAPHICMODE, GET SCALE {int R; _displaycursor( J3CURSORON ); " setvideomode DΕFAULTMODE ); cόut « " [<0 EXiη, color_map (0-NTSC, 1-HSI,2-NEW,3-RGB,4- LUMIN_THR 5-HSI\n"; cout«"WIN_SIZE\n "; cin »MAP»winsize.c; _displaycursor( J3CURSOROFF ); _setvideomode(~GRAPHMODE ); make_palette(); return R; } int get number 3 f(FILE f) // INITIALISATION GRAPHICMODE, GET SCALE {int R; fscanf(f," %d %d ",&MAP, &(winsize.c)); return 1; } //=======================================================: int picturejnf(char *name,SCR_PNT *vertexes) {int i; char new name[25]; FILE *datfp; strcat(strcpy(new_name,name),".sgn"); if(!(datfp=fopen(new_name,"r"))) return 0; fscanf(datfp,"%s\n",new_name); for(i=0;i<4;i++) fscanf(datfp,"%d %d\n",&(vertexes[i].c),&(vertexes[i].r)); fclose(datfp); return 1; } //================================= //================================================.======== int picture inf_num 2(char *name,SCR PNT * vertexes,short n.char *ext-".sgn :: ) {int i,j; char new name[45]; FILE *datfp; strcat(strcpy(new_name,name),ext); if(!(datfp=fopen(new_name,"r"))) return 0; fscanf(datfp,"%*s % * s %*s % * s % * s \n"); fscanf(datfp,"%s %s %s %s %s",&f_name,&FILE_name, &FRAME_Name, &STRING_name, &SIGN_name)7 for(j.=0;j<n+1;j++) for(i=0;i<4;i++) if(fscanf(datfp,"%d %d\n" > &(vertexes[i].c),&(vertexes[i].r))==EOF) {fclose (datfp); return 0;} fclose(datfp); return 1 ; } Tvoid write_signjnf(char * pr,PCT pict_now) { char fl Jp[50],f_name[9]; int FLG; FILE * dathere,*database; _splitpath( pr, drive, dir,f_name,ext ); strcat(strcpy(fljp,pr),".sgn"); dathere=fopen(flJp,"w"); FLG=_access("PROTODB.1", 0 );// -1 if not exist if(!(database=fopen("PROTODB.1","a"))) {strcpy(fIJp,"CAN NOT CREATE D_BASE FILE"); exit(-1);} fprintf(dathere, " WIN name FILE name FRAME_Name STRING_name SIGN_name\n "); fprintf(dathere,"%8s %9s %10s %11s %9s \n",f_name, FILE_name, FRAME Name, STRING name, SIGN name); if(FLG) fprintf(database, " WIN_name FILE_name FRAME Name STRING name SIGN_name\n "); fprintf(database,"%8s %9s %10s %11s %9s \n",f_name, FILE_name, FRAME_Name,STRING_name,SIGN_name); fprintf(dathere,"%d 0\n",pict_now.s_cols-1 ); fprintf(dathere,"%d %d \n",pict_now.s_cols-1 ,pict_now.s_rows-1 ); fprintf(dathere," 0 %d\n",pict_now.s rows-1); fprintf(dathere," 0 0\n"); fclose(dathere); fclose(database); } */ //=============================================== int picturejnf_num(char *name,SCR_PNT * vertexes, short n) {int i,j; char new_name[25]; FILE * datfp; strcat(strcpy(new_name,name),".sgn"); if(!(datfp=fopen(new_name,"r"))) return 0; fscanf (datfp ,"%s\n", new_name); i for(j=0;j<n+1;j++) for(i=0;i<4;i++) if(fscanf(datfp,"%d %d\n",&(vertexes[i].c),&(vertexes[i].r))==EOF) {fclose (datfp); return 0;} fclose(datfp); return 1 ; } int picturejnf_num_new(char * name,SCR_PNT * vertexes,short n) {int i,j; char new_str[80]; FILE *datfp; int r,FLG=0; strcat(strcpy(new_str,name),".sgn"); if(!(datfρ=fopen(new str,"r"))) return 0; r=fscanf(datfp,"%[ Λ \n]s ",new_str); r=fscanf(datfp," %[ A \n]s ",new_str); if(__iscsymf( (int)new_str[0]))//FILE INFORMATION ) //(letter or underscore) {sscanf(new_str," %s %s %s %s ",&FILE_name, &FRAME_Name, &STRING_name, &SIGN_name); r=fscanf(datfρ," %[ Λ \n]s ",new str); } for(j=0;j<n+1 ;j++) for(i=0;i<4;i++) {if(FLG) if(fscanf(datfp," %[ Λ \n]s",new_str)==EOF) {fclose (datfp); return 0;} FLG=1; sscanf(new_str," %d %d",&(vertexes[i].c),&(vertexes[i].r)); } fclose(datfp); return 1; } //========================================================== #include <vmemory.h> #iπclude <stdio.h> #include <stdlib.h> #include <conio.h> #inciude <malloc.h> #include <float.h> #include <graph.h> #include <string.h> #in ude "lns_corr.h" //#include "tem_ρlt7.h" #include "corjnc.h" //#include "deb_out.h" #define MAX_LINE 1024 extern FILE * PROTOCOL; extern double GAMMA,Thresh_mdl; extern short MAP; extern short VOITING; extern struct _videoconfig vc; extern char f_name[40],FILE_name[40], FRAME Name[40], STRING_name[40], SIGN_name[40]; //==================±============================= void draw int(short st,shortw,COLOR_VEC intr); //================================================ void draw_color_corr 1 (COLOR VEC corr.short F, short CH HIGHT, short CH_BASE,double THRESH, short pos_now, short size); //============================= void draw_chart(double *distJine,short n.double max value=0. short CH HIGHT= 100. short CH_BASE= 480,double THRESH=0, short t_pos=60); //================================================ #define HOR_HARM 2 #define VERT_HARM 4 II inline COLOR_VEC sign for_col(short d, COLOR_VEC col) { COLOR_VEC out; int i; for (i=0;i<3;i++) out.c[i]= d?col.c[i]:-col.c[i]; return out; 113 } II- /*COLOR_VEC int_value 1 (PCT w.double Thr, COLOR_VEC ( * pJunct)(COLOR_RGB p1.double Thresh mdT),AVERAGE_VEC w_av) {COLOR VEC col,sum[9][9].out,c1; const COLOR_VEC z={0,0,0}; short hj,vj,i,x,y,h,v, f.alf_x=w.s_cols>>1 ,half_y=w.s_rows»1 , quot__x=w.s_cols»2,quot_y=w.s_rows»2; long n; for(h=0;h<HOR HARM+1;h++) for(v=0;v<VERT HARM+1;v++) sum[v][h].c[θT=sum[v][h].c[1]=sum[v][h].c[2]=0.0; n=w. s_cols * w. s ows; n*=n; for(y=0;y<w.s rows;y++) for(v=0;v<VERT HARM+1;v++) { v_t=y*((v+1)»1); vj=(vj+(v & 0x0001 ? quot_y:0))/half_y; vj &= 0x0001; for(x=0;x<w.s_cols;x++) {col=pJunct(w.get_pixel(y,x),Thr); c1= sign for col(vJ,col); for(h=0;h^HOR_HARM+1 ;h++) { h t=x*((h+1)»1); hj=(h t+(h & 0x0001 ?quot x:0))/half ς hj &= 0x0001; c1= signJor_col(hJ,d); for(i=0;i<3;i++) sum[v][h].c[i]+=c1.c[i]; } } } double sO,dd,max_v=0,th; for(dd=i=0;i<3;i++) {for(s0=h=0;h<H0R_HARM+1 ;h++) for(v=0;v<VERT HARM+1;v++) if(h||v) s0+=sum[v][h].c[i]*sum[v][h].c[i]; m for(i=0;i<3;i++) {th=out.c[i]/max_v; // THRESHOLDING if(th<0.2) out.c[i]=0; } return out; } */ //======================================================== COLOR_VEC ( * PointColFunct())(COLOR_RGB p1, double Thresh_mdl) { switch ( MAP) {case NTSC:retum(color_space_NTSC); case New_plan:return(color_space_NEW); case HSI:return(color_space_RGB); case RGB:return(color_space_RGB_simple); case LUMIN_THR:return(color_space_LUMlN_THR); case IHS:retum(color_spaceJHS); }; return NULL; } //========================================================= const short CH_HIGHT_D=100, CH BASE_D=470, CH_HIGHT=100, CH_BASE=450, t_pos=40; / ===================================================== double scalejact=1; /====================================================== void corr_win_proto(PCT win_source,PCT Proto, SCR_PNT win_size .short win_step,double CORR THRESH.short *StriρEnds) { short i; char mess[40]; short F=0; COLOR_VEC (*p_funct)(COLOR_RGB p1, double Thresh_mdl); pJunct-PointColFunctO; PCT win(win_size.c,win_size.r); PCT tag(win_size.c,win_size.r); SCR PNT stj,st_win; AVERAGE_VEC middle win[64],middlejag; const AVERAGE_VEC z={{0,0,0},{0,0,0}}; COLOR VEC *corr_now,cr; const COLOR_VEC z_col={0.0,0.0.0.0}; int line_size=win_source.s_cols+Proto.s_cols; //memory allocation ι'ε if((corr_now= (COLOR_VEC * ) malloc( sizeof(COLOR_VEC) * (sizeJ)line_size * 3))==NULL) {printf("WIN NOT MEMORY'); return;}; stj.r=0; double dd; short StripStart, StripStop; short PartNurn; k=PartNum=0; while(StripEnds[PartNum]>=0) {StripStart=StripEnds[PartNum++]; StriρStop=StripEnds[PartNum++]; for (st_wiπ.c=StripStart; st_win.c+win_size.c<=StripStop;st win.c+=win_step,k++) { FLG_COL=1; for(i=0;i<line_size;corr_now[i++]=z_col); win.loadjemplate(win_source,st_win); middIe_win[k]=average(win,Thresh_mdl,pJunct); #ifdef MICI #endif const COLOR_VEC z_UNIT={1.0,1.0.1.0}; for (stj.c=0;st Lc<=Proto.s cols-win_size.c;st tc++) { //============================================ tag. load Jemplate(Proto, st J); middleJag=average(tag,Thresh mdl.p funct); // DIFF ABS VALUES #ifdef SINGL_VAL cr=template conv 1( tag,win,Thresh_mdl,z UNIT.pJunct); strcpy(mess? VECTOR Approach to CORRELATION "); corr now[st t.c]=Correlation single 1(cr,middlejag,middle win[k],z_ UNIT); #ifdef ABS_VALUE strcpy(mess," DIFF ABS VALUES/ max ABS VALUES"); cr= template_abs_diff_1 (tag,win,Thresh_mdl,z_UNIT,p_funct, middlejag,middle_win[k]); #else cr=template conv 1( tag,win,Thresh_mdl,z UNIT.p funct); strcpy(mess? PEARSON CORR. "); corr_now[stJ.c]=Correlation(cr.middleJag,middle_win[k],z_UNπ " ); #endif /% #endif // ONLY LUMINANCE // strcat(mess," ALL 3 COMP"); strcat(mess," Only 0 COMP"); corr_now[stJ.c].c[1]=corr_now[stJ.c].c[2]= corr_now[stj.c].c[0]; #ifdef MIC I draw color_corr 1( corr_ήow[stJ.c], ' FLG_COL,CH_HIGHT_D,CH_BASE_D,CORR_THRESH, st Lc.Proto.s cols); FLG COL=0; #endϊf } //======FILL PROTOCOL //$ WILL BE USED AS SEPARATOR FOR READING fprintf(PROTOCOL,"$\t%s\t$\t%4d\t $\n",mess, st_win.c); for(i=0;i<Proto.s_cols;i++) //ONLY 0 COMP fprintf(PROTOCOL,"%6g\t",corr now[i].c[0]); fprintf(PROTOCOL," \n"); } } win.free_PCT(); tag.free_PCT(); free((void *)corτ_now); return ; } __ //============================================== void draw chart(double * distJine,short n.double max_value, short CH HIGHT, short CH_BASE,double THRESH. short t_pos) {short i,j; double p, crit=max_value; if(!max_value) for (i=0;i<n;i++) crit=(distjine[i]>crit)? distjine[i]:crit; else crit=max_value; if(!crit) crit=1; p= CH HIGHT*(1-THRESH/crit); _move7o( 0,CH_BASE-CH_HIGHT ); M Jineto(n,CH_BASE-CH_HIGHT); _moveto(0,CH_BASE-(short)p); Jineto(n,CH_BASE-(short)p); _moveto( (short) O.(short) CH_BASE ); for (i=0;i< min(n,vcnumxpixels);i++) (j=CH BASE-CH HIGHT+(short)(distJine[i] * CH_HIGHT/crit); ifO<0) // getch() else if(!Jineto( i,j)) // getch() } if(t_pos) _settextposition( t_pos,30); char buffer[30]; sprintf(buffer, "MAX = %f10 ", crit ); _outtext( buffer ); } //========================================================= void draw iπt(short st,short w,COLOR VEC intr) {short CH HIGHT=100. CH_BASE=200; double p; _setcolor( color_num(240,240,240)); setcolor( color num(240,0,0)); ~p=CH_BASE-CH_HIGHT*intr.c[0]; _moveto( st,(short)p); Jineto(st+w,(short)p); _setcolor( color_num(0,240,0)); p=CH_BASE-CH_HIGHT * intr.c[1 ]; _moveto( st,(short)p); Jineto(st+w,(short)p); _setcolor( color num(0,0,240)); p=CH_BASE-CH_ llGHT*intr.c[2]; _moveto( st,(short)p); Jineto(st+w,(short)p); } //====================================== void draw_color_corr(COLOR_VEC corr,COLOR_RGB * corr_old,short F, short CH HIGHT, short CH_BASE,doubie THRESH, short pos_now) {double p; short j; if(F) { _setcolor( color_num(240,240,240)); p= CH_HIGHT * (1 -THRESH); _moveto( 0,CH_BASE-CH_HIGHT ); Jineto(512,CH_BASE-CH_HIGHT); _moveto(0,CH_BASE-(short)p); Jineto(512,CH_BASE-(short)p); } _setcolor( coior_num(240,240,240)); _moveto( pos_now,corr_old->r); j=CH_BASE-CH_HIGHT+(short)(corr.c[0] * CH_HIGHT); Jineto(pos_now+1 ,j); corr_old->r=j; _moveto( pos_now,corr_old->g); _setcolor( color num(240,0,0)); j=CH_BASE-CH HIGHT+(short)(corr.c[1] * CH_HIGHη; Jineto(pos_now+1 ,j); corr_old->g=j; _moveto( pos_now,corr_old->b); _setcolor( color_num(0,240,0)); j=CH_BASE-CHJHIGHT+(short)(corr.c[2]*CH_HIGHT); Jineto(pos_now+1 ,j); corr old->b=j; } //========================================================= void draw color_corr 1(COLOR_VEC corr.short F, short CH_HΪGHT, short CH_BASE,double THRESH, short pos_now, short size) { short j,k,l,i,st; static short real_size,pos_old; short POS; static COLORJ GB corr_old; real_size=size*scalejact; POS=10+pos_now*scale Jact; _setcolor( color_num(2407240,240)); if(F) { setcolor( color num(0,0,0)); ~rectangle( _GFILL!NTERIOR,0,CH BASE-3 * CH HIGHT- (CH HIGHT_D»1), real_size ,CH_BASE); setcolor( color num(240,240,240)); corr old.r=k=CH BASE-2*CH_HIGHT-40; st=CH-HIGHT/10; for(i=0;i<3;i++) l-\n { _moveto( 10,k-CH_HIGHT); Jineto(10,k); lineto(10+real_size,k); ~moveto(10,k-CH HIGHT * THRESH); ~lineto(10+real size,k-CH_HIGHT * THRESH); f~or(l=0,j=1;j<1 lj++) {l+=st; moveto( G==5)?5:(G==10)?0:7) • ,k-l); Jineto(10,k-I); } k+=(CH_HIGHT+20); } corr_old.g=corr_old.r+CH_HIGHT+20; corτ_pld.b=corr_pld.g+CH_HIGHT+20; pos old=10; } _setcolor( color_num(240,240,240)); k=CH_BASE; moveto( pos_old,corr old.b); F=k-(short)(corr.c[2] * CH_HIGHT); Jineto((short)(POS) ,j); corr_old.b=j; k-=(CH_HIGHT+20); moveto( pos_old,corr old.g); pk-(short)(corτ.c[1 ]*CHJHIGHT); Jineto((short)(POS),j);~ corr_ ld.g=j; k-=(CH_HIGHT+20); moveto( pos_pld,corr old.r); k-(short)(corr.c[0] * CH[_HIGHT); Jineto((short)(POS) ,j); corτ_old.r=j; pos_ ld=POS; } AOO void corτ_win_proto(PCT win_source,PCT Proto, SCR_PNT win_size .short win_step, double CORR_THRESH, short *StripEnds) ; ao i ORIGIN = PWB ORIGIN_VER = 2.0 PROJ = PRT_ANL2 PROJFILE = PRT_ANL2.MAK BUILDDIR = obj DEBUG = 1 BRFLAGS = /o obj\$(PR0J).bsc BSCMAKE =bscmake SBRPACK =sbrpack NMAKEBSC1 = set NMAKEBSC2 = nmake BROWSE = 1 CC =cl CFLAGS G = ΛΛ/2 /BATCH /FR$ * .sbr CFLAGS D =/f/Zi/0d CFLAGS R =/f-/Ot/0i/OI/Oe/Og/Gs CXX =cl CXXFLAGS_G = /AL ΛΛ/4 /G2 /D_D0S /BATCH /FR$*.sbr CXXFLAGS_D = /f- /Od /FPiδ7 /Zi /DMICI /DSINGLE_WIN CXXFLAGS R = /f-/0t/OI/Og /Oe/Oi/FPiδ7/Gs /DMICI /DSINGLE WIN MAPFILE D = NUL MAPFILE R = NUL LFLAGS_ "( 3 = /NOI /STACK32000 /BATCH /ONERROR:NOEXE LFLAGS D =/CO/FAR/PACKC LFLAGS.R =/EXE/FAR/PACKC LINKER = link ILINK = ilink LRF = echo > NUL ILFLAGS =/a/e LLIBS_G = graphics lafxcr CVFLAGS =/25/S RUNFLAGS = ..\win4\s1600 corrthr.06 PACK_SBRS = 1 FILES = PRT_ANL2.CPP .ΛLIBWICALLOC.CPP ..\LIB\PROJCTN7.CPP\ ..\LIB\PIC_M7.CPP ..\LIB\RES MCH7.CPP PRT 2MD.CPP OBJS = obj\PRT_ANL2.obj objWICALLOC.obj obj\PROJCTN7.obj objΛPIC M7.obj\ obj\RES_MCH7.obj objΛPRT 2MD.obj SBRS = obj\PRT_ANL2.sbr objWICALLOC.sbr obj\PR0JCTN7.sbr objΛPIC M7.sbr\ obj\RES_MCH7.sbr obj\PRT_2MD.sbr all: obj\$(PROJ).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .cpp £03. obj\PRT_ANL2.obj : PRT ANL2.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\ " conio.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\time.h C:\C700\INCLUDE\ctype.h\ C:\C700\INCLUDE\fstream.h C:\C700\MFC\INCLUDE\afx.h prt_anls.h\ PIC_PRO.h C:\C700\INCLUDE\iostream.h C:\C700 IFC\INCLUDE\afx.inl\ ..\LIB\projctn7.h ..\LIB\pic__mch7.h ..\LIB\res_mch7.h\ c:\ilya\lib\linjrn7.h C:\C700\INCLUDE\direct.h C:\C700\INCLUDE\ios.h\ C:\C700\INCLUDE\streamb.h C:\C700\INCLUDE\istream.h\ C:\C700\INCLUDE\ostream.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\vmemory.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /Foobj\PRT_ANL2.obj PRT_ANL2.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /Foobj\PRT_ANL2.obj PRT_ANL2.CPP « IENDIF objΛPRT ANL2.sbr : PRT ANL2.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE~conio.h C:\C700\INCLUDE\stdio.h\ C:\C700\INCLUDE\string.h C:\C700\INCLUDBgraph.h\ C:\C700\INCLUDE\float.H C:\C700\INCLUDE\time.h C:\C700\INCLUDE\ctype.h\ C:\C700\INCLUDE\fstream.h C:\C700\MFC\INCLUDE\afx.h prt anls.h\ PIC_PRO.h C:\C700\INCLUDE\iostream.h C:\C700\MFC\INCLUDE\afx.inl\ ..\LIB\projctn7.h ..\LlB\pic_mch7.h ..\LIB\res_mch7.h\ c:\ilya\lib\linjm7.h C:\C700\INCLUDE\direct.h C:\C700\INCLUDE\ios.h\ C:\C700\INCLUDE\streamb.h C:\C700\INCLUDE\istream.h\ C:\C700\INCLUDE\ostream.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\vmemory.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PRT_ANL2.sbr PRT_ANL2.CPP « IELSE @S(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) 3£>3 $(eXXFLAGS_R) PRT_ANL2.CPP « IENDIF objWICALLOC.obj : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C.\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloc.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /FoobjWICALLOC.obj .ΛLIBWICALLOC.CPP « IENDIF objWICALLOC.sbr : .ΛLIBWICALLOC.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\malloch IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobjWICALLOC.sbr .ΛLIBWICALLOC.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\VICALLOC.sbr .ΛLIBWICALLOC.CPP « IENDIF obj\PROJCTN7.obj : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h .ΛLIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\lNCLUDBistream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PROJCTN7.obj ..\LIB\PROJCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PROJCTN7.obj .ΛLIB\PROJCTN7.CPP a >4 « IENDIF obj\PROJCTN7.sbr : ..\LIB\PROJCTN7.CPP C:\C700\INCLUDE\graph.h\ C:\C700\INCLUDE\stdlib.h C:\C700\INCLUDE\iostream.h ..\LIB\projctn7.h\ C:\C700\INCLUDE\ios.h C:\C700\INCLUDE\streamb.h\ C:\C700\INCLUDE\istream.h C:\C700\INCLUDE\ostream.h\ C:\C700\INCLUDE\math.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PROJCTN7.sbr ..\LIB\PROJCTN7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PROJCTN7.sbr ..\LIB\PR0JCTN7.CPP « 1ENDIF objΛPIC M7.obj : ..\LIB\PIC_M7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700MNCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float. H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ ..\LIB\vicalIoch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFl_AGS_ " ) /Foobj\PIC_M7.obj ..\LIB\PIC_M7.CPP « lELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /Foobj\PICJv17.obj ..\LIB\PIC_M7.CPP « IENDIF objΛPIC M7.sbr : ..\LIB\PIC_M7.CPP C:\C700\INCLUDBstdlib.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\math.h\ C:\C700\INCLUDE\io.h C:\C700\INCLUDE\fcntl.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\float. H C:\C700\INCLUDE\malloc.h ..\LIB\phdr.h\ ..\LIB\vicalloch ..\LIB\pic_mch7.h C:\C700\INCLUDE\vmemory.h\ ..\LIB\projctn7.h 3£>L IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PIC_M7.sbr ..\LIB\PIC_M7.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PIC_M7.sbr ..\UB\PIC_M7.CPP « IENDIF IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_R) /Foobj\RES_MCH7.obj ..\LIB\RES_MCH7.CPP « IENDIF obj\RES_MCH7.sbr : ..\LIB\RES_MCH7.CPP C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\vmemory.h ..\LIB\pic mch7.h ..\LIB\res mch7.h\ C:\C700\INCLUDE\graph.h ..\LIB\projctn7.h C:\C700\INCLUDE\math.h !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_D)7FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « 1ELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFLAGS_R)7FRobj\RES_MCH7.sbr ..\LIB\RES_MCH7.CPP « IENDIF obj\PRT_2MD.obj : PRT_2MD.CPP C:\C700\INCLUDE\io.h C:\C700\INCLUDE\iostream.h\ C:\C700\INCLUDE\fstream.h prt_anls.h PIC_PRO.h C:\C700\INCLUDE\ios.h\ C:\C700\INCLUDE\streamb.h C:\C700\INCLUDBistream.h\ C:\C700\INCLUDE\ostream.h ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\linjrn7.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\direct.h C:\C700\MFC\INCLUDE\afx.h\ C:\C700\INCLUDE\math.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\time.h\ C:\C700\MFC\INCLUDE\afx.inl !IF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_D) /Foobj\PRT_2MD.obj PRT_2MD.CPP « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Foobj\PRT_2MD.obj PRT_2MD.CPP « IENDIF obj\PRT_2MD.sbr : PRT_2MD.CPP C:\C700\INCLUDE\io.h C:\C700\INCLUDE\iostream.h\ C:\C700\INCLUDE\fstream.h prt_anls.h PIC_PRO.h C:\C700\INCLUDE\ios.h\ C:\C700\INCLUDE\streamb.h C:\C700\INCLUDE\istream.h\ C:\C700\INCLUDE\ostream.h ..\LIB\projctn7.h ..\LIB\pic_mch7.h\ ..\LIB\res_mch7.h c:\ilya\lib\lin trn7.h C:\C700\INCLUDE\stdlib.h\ C:\C700\INCLUDE\dlrect.h C:\C700\MFC\INCLUDE\a6 h\ C:\C700\INCLUDE\math.h C:\C700\INCLUDE\vmemory.h\ C:\C700\INCLUDE\graph.h C:\C700\INCLUDE\string.h\ C:\C700\INCLUDE\stdio.h C:\C700\INCLUDE\time.h\ C:\C700\MFC\INCLUDE\afx.inl IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FRobj\PRT_2MD.sbr PRT_2MD.CPP « 1ELSE • @$(CXX) @«obj\$(PROJ).rsp Zs $(CXXFLAGS_G) $(CXXFLAGS_R) /FRobj\PRT_2MD.sbr PRT_2MD.CPP « IENDIF obj\$(PROJ).bsc : $(SBRS) $(BSCMAKE) @« S(BRFLAGS) $(SBRS) « obj\$(PROJ).exe : $(OBJS) -$(NMAKEBSC1) MAKEFLAGS= Qon -$(NMAKEBSC2) S(NMFLAGS) -f $(PROJFILE) obj\$(PROJ).bsc IIF $(DEBUG) $(LRF) @«obj\$(PROJ).lrf $(RT OBJS: = + Λ ) $(OBJS: = + Λ ) $@ $(MAPFILE_D) $(LIBS: = + ;r ) + $(LLIBS_G: = + Λ ) + $(LLIBS_D: = + ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_D); « IELSE $(LRF) @«obj\$(PROJ).lrf $(RT_OBJS: = + Λ ) $(OBJS: = + Λ ) $@ $(MAPFILE_R) $(LIBS: = + ) + $(LLIBS G: = + ) + $(LLIBS R: = +* ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « IENDIF $(LINKER) @obj\$(PROJ).lrf .cpp.obj : IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS G) $(CXXFLAGS_D) /Fo$@ $< « IELSE @$(CXX) @«obj\$(PROJ).rsp /c $(CXXFLAGS_G) $(CXXFLAGS_R) /Fo$@ $< « IENDIF .cpp.sbr : <3θ8 IIF $(DEBUG) @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS_G) $(CXXFLAGS_D) /FR$@ $< « IELSE @$(CXX) @«obj\$(PROJ).rsp /Zs $(CXXFLAGS G) $(CXXFL_AGS_R)7FRS@ $< « IENDIF run: obj\$(PROJ).exe obj\$(PROJ).exe $(RUNFLAGS) debug: obj\$(PROJ).exe CV $(CVFLAGS) obj\$(PROJ).exe $(RUNFLAGS) aoq #ifndef PIC_PRO #defιne PIC_PRO #include <stdlib.h> #include <direct.h> #include <afx.h> #include <pic_mch7.h> CString MakeName(char * p ); CString MakeName(CString N); const SCR_PNT z_0(0,0); class PRT:public PCT {public: //information CString PathName; CString FRAME_Number; CString STRING name; CString SIGN_name; short Pos; // Position in the string long NumberOfChk.MaxNum; double *Charact; //models PRT::~PRT() {this->free_PCT(); Pos=0; if(MaxNum) delete Charact; Charact=NULL; MaxNum=NumberOfChk=0; } II- PRT::PRT() {NumberOfChk=MaxNum=s cols=s rows=0; Charact=NULL;pict=NULL;~ } II- PRT::PRT (short n cols, short n rows) {*(PCT *)this=PCT::PCT(n_cols,n_rows); NumberOfChk=MaxNum=0; Charact=NULL; } //==================================== int read_proto_SGNQ { CString new_name(' ',δ0); PathName=MakeName(PathName); ait- new_ ame=PathName+".sgn"; char now[δ0]; FILE * datfp; if(!(datfp=fopen((const char * )new_name,"r"))) return 1; if(fscanf(datfp,"%*[ Λ \n]s ")==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;FRAME_Number=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;STRING_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN_name=now; STRING_name.MakeUpper(); SIGN_name.MakeUpper(); • fclose(datfp); return 0: ERR:fclose (datfp); return 1 ; } //========================================================== int proto_storage_rgb(char * name, struct _yideoconfig vc) {*(PCT * )this=sign_storage_rgb(name,vc); if (!s_cols) return 1; PathName=MakeName(name); if (read_proto_SGN()) {free_PCT(); return 1 ; } return 0; } II int read_proto_DBC(FlLE * datfp) { char now[60]; if(fscanf(datfp,"%s ",now)==EOF)goto ERR;PathName=MakeName(now); if(fscanf(datfp,"%s ",now)==EOF)goto ERR;FRAME_Number=now; if(fscanf(da-fp,"%s ",now)==EOF)goto ERR; STRI N G_name=now; if(fscanf(datfp,"%s ",now)==EOF)goto ERR; SIGN name=now; if(fscanf(datfp,"%d ",&(this->s_cols))==EOF)goto ERR; FRAME_Number.MakeUpper(); STRING_name.MakeUρper(); SIGN_name.MakeUpper(); return 1 ; ERR: return 0; } an int alloc Charact_dbl(long Num) { if(!(Charact=new double[Num])) return 1; MaxNum=Num; NumberOfChk=0; return 0; } //_ void free_Charact() {delete Charact; Charact=NULL; } II int read_Charact_dbl(FILE *inp,long Num) {short i; double d; if(MaxNum<(NumberOfChk+Num)) return 1; for (i=0;i<Num;i++) {if(fscanf(inρ,"%lf ",&d) —EOF) return 1; if(fabs(d)<1.0e-4) d=0; Charact[NumberOfChk]=d; NumberOfChk++; } return 0; } II double CorrValue(short WNum.short Pnum) {return ( * (Charact+(long)WNum * s_cois+Pnum)); } II }; /===================================== #defιne UnKnown -1 / =====================================: typedef struct { short n; // voiting numbers short pos; // position in string double value; //value } RSLT; II void HistCollect(short NOfWin.short St.short Fin.PRT &Db); RSLT LineEstimation (short TagSize, PRT &Db,short NOfWin, short WSize.double Thr); int Linelnf(const PRT &P, PRT T, short rw, short Xpos.struct _videoconfig vc); double Linlnter( PRT &P,short WNum.short WSize .double Pt); 5-1 a void HistThresh(short *H,short *BotThr,short TopThr.short num); #endif ai3 #ifndef DECISION #defιne DECISION #include <iostream.h> #include "PIC_PR0.h" #defιne UnKnown -1 typedef struct { short n; // voiting numbers short pos; // position in string double value; //value } RSLT; II void HistThresh(short *H,short *BotThr,short TopThr.short num) void HistCoIlect (short * * His, short NOfWin, PRT &Db); RSLT LineEstimation (short TagSize, PRT Db.short NOfWin, short WSize.double Thr); int Writeϋnelnf(PRT &P, PRT T, short rw, short Xpos); 3LH #ifndef LNS CORR #define LNS_CORR #include "projctn7.h" #include "pic_mch7.h" #include "res_mch7.h" #include "iin trn7.h" /#include "tem_plt7.h ,, #defιne NAMEJ.ENGTH 40 #define GRAPHMODE _VRES256COLOR #defιne HistDim 101 #endif 9 IS // PRT_ANLS // Module analyses file PROTOJ .dbc (output of LNS_CORR), //calculates histogramme functions of PROTO_1 in file PROTO_1.hs2. //Bisides that it asks a possibilites to connect PROTOJ //with another sign in one strip. // // COMMAND STRING // // prt_anis <PROTO_1_Name> [CommandFile] // // <PROTO_1_Name> File name of PROTOTYPE without extention // [CommandFile] Optional ASCI file with a run time parameters. // // INPUT // .DBC, .RGB files of prototypes and corresponding .SGN files created by // modules LNS_CORR and MAKEPRB. // RUN TIME parameters: // // <CORR_THR> threshold for sign linking // We have used 0.6; // If cross correlation axceede the <CORR_THR> the number of // string will be asked. Negative number cause not including the // connection in list. //SEE ALSO FILE "PRT ANLS.INI" // OUTPUT // PROTO_1.HS2 - Histogramme ; // LINECOL.PRT - File collects an information about sign linking // in accordance with <CORR_THR> and our response. // FILE structure: //(example file string start after char # that not belongs to file // #LineCollection // #Line # FName #1 FName #2 Pos ... // #1 c:\ilya\winps\s160JD c:\ilya\winps\s160__6 16 // #1 c:\ilya\winps\s160_0 c:\ilya\winps\s160 15 37 //EOF // Here 1 Line number named through the keyboard //....s160_0 - PROTOJ name; //....s160_6 and s160_15 name of prototypes linked with a PROTOJ // in one strip; // 18 and 37 positions of corresponding prototypes start relative to // 0 colomn of PROTOJ (PROTOJ STARTS in 0 colomn of PROTOJ) #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <string.h> Λ ι > #include <graph.h> #include float.H> #include <time.h> #include <ctyρe.h> #include <fstream.h> #include <afx.h> #include "prt_anls.h" #include "PIC_PRO.h" #define MaxNumOfPicks 20 const short MaxNumOfWin =25; #define MaxProtNum 25 short Hist[MaxNumOfWin][HistDim]; cha cha dou short MAP; short VOITING=3,TAG_hight; struct _videoconfιg vc; double sh[4]={0,0,0,0}; int get_number_4(); // INITIALISATION GRAPHICMODE, GET SCALE int get number_4J(FILE *f); // INITIALISATION GRAPHICMODE, GET SCALE ψφψψtfφ ψψψφφψwψψψψφψψφφvψψ CString PROTOCOL_NAME; of stream LineC; //============ OpenLineCollection void OpenLineCol(const char*name) { LineC. open(name,ios::out|ios::app|ios::out|ios::nocreate); if(LineC.failO) {LineC.ciear(O); LineC. open(name,ios::out|ios::app|ios::out|ios::noreplace); if(LineC.failO) {LineC. clear(O); cout « "CAN NOT OPEN LineCollection"; GRAPH_OUT(-1); } } } //========================================================== SCR_PNT winsize; //===============================================—=== int main(int argc.char * argvQ) { int FLG_F=0; FILE *datainf; short n=0; SCR_PNT t_pos; if((argc != 2) && (argc 1=3)) { printf(" proto file\n"); FLG_F=0; retum(1); } else if(arαc ==3) {FLG_F=1 ; if(!(datainf=fopen(argv[2],"r"))) return 0; } if(FLG_F) get_number_4J(datainf); // GET SCALE else get_number_4(); PRT prototype; // ================ GRAPHICS START if(GRAPHICS START(&vc,GRAPHMODE)) GRAPH OUT(-1); //================= if(prototype.proto_storage_rgb(argv[1],vc)) {printfC'SGN TARGET not exist"); GRAPH_0UT(-1 ); } // READ .DBC FILE AND STORED Correlation Function //========= PROTOTYPE LOOP OVER DBASE .dbc PRT DbProto[MaxProtNum]; CString DbName=argv[1]; DbName+=".dbc"; FILE *Db=fopen((const char *)DbName,"r"); if(!Db) {printffDBase not exist"); GRAPH_OUT(-1 );} // DEBUG Split two rows short WinSize; char AA [128],SPACE[14]; fscanf(Db,"%[ Λ \n]s ", AA); fscanf(Db," %[ Λ \n]s", AA); fscanf(Db,"%*s % * s % * s % * s % * s %d %s ",&WinSize,SPACE); const ' MaxNumberOfWin=30; short NumberOfWin=0;//=prototype.s_cols/WinSize; short iDbProto=0; fscanf(Db,"%[ Λ \n]s ", AA); short i,j; while( DbProto[iDbProto].read_proto_DBC(Db) ) { if(DbProto[iDbProto].alloc_Charact_dbl(MaxNumberOfWin*DbProto[iDbProto] .s_cols) ) {printff NOT MEMORY for data-"); GRAPH_OUT(-1 );} fscanf(Db," %[ Λ \n]s ",AA); // DEBUG Split one row while(!feof(Db)) { NumberOfWin++; if(DbProto[iDbProto].read Charact dbl(Db,DbProto[iDbProto].s_cols)) {print. (" END of DB"); GRAPH_OUT(-1 );} fscanf(Db." %[ Λ \n]s ".AA); // DEBUG Split one row } iDbProto++; } fclose(Db); // END READ .DBC FILE AND STORED Correlation Function OpenLineCol(LineColName); LineC« "LineCollection \nLine #\t FName #1\t FName #2\t Pos ... \n"; //LOOP over targets int LN.p; RSLT LineEst; short St,Fin; for (i=0;i<MaxNumOfWin;i++) for O=0;j<HistDim;Hist[i] ++]=0); //Miki's Threshold short PrNumber=-1 ; f or(i=0; i<iDbProto; i++) if(DbProto[i].PathName==prototype.PathName) {PrNumber=i; break;} // IF AutoCorr absence PrNumber=-1 // Line linking and noise calculation for (i=0:i<iDbProto;i++) { St=0; Fin= DbProto[i].s_cols; if(i!=PrNumber) {LineEst=LineEstimation(prototype.s_cols, DbProto[i],NumberOfWin, WinSize, CORR THRE SH); if (LineEst.n) { p=LineEst.pos-DbProto[i].s_cols; // DbProtoStart LN=Linelnf(ρrototype, DbProto[i], vc.numtextrows, p+10,vc); if (LN>=0) {if (p>0) St=prototype.s_cols-p; else Fin=-p; LineC«LN«Λt , «ρrototype.PathName« Λt'« DbProto[i]. PathName«Λt'«p«Λn'; } } } //Histogramm calculation HistCollect(NumberOfWin,St,Fin,DbProto[i]); } LineC.closeO; // RESULT OUT PROTOCOL NAME=argv[1]; PROTOCOL_NAME+=".hs2" ; OρenϋneCol((const char*)PROTOCOL_NAME); LineC«"Histogrammes\n"; LineC«argv[1]«"\t"«prototype.SIGN_name«'\n'; LineC«"NumberOfWindows\t"«NumberOfWin«'\n'; LineC«"NumberOfBins\t"«HistDim« , \n'; LineC«"Win_pos\n"; forO=Oj<NumberOfWin;j++) {LineC«j * WinSize«" \t"; for(i=0;i<HistDim;i++) LineC«Hist[j][i]«" \t"; LineC«Λn'; } LineC.close; //CORRELATION PROCESSING GRAPHJDUTO; return(O): } // / • void oe _shiftJ(FILE f.double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; for(i=0;i<4; i++) { fscanf(f,"%lf %lf\n",sh+i++,sh+i); } // void get_shift(double * sh) // INITIALISATION GRAPHICMODE, GET SCALE {int i; cout« "vertexes shift over rows ( topjϊght, bottom_right, bottomjeft, topjeft %\n"; t for (i=0;i<4; i++) cin»sh[i]; } int get_number_4() // INITIALISATION GRAPHICMODE, GET SCALE {int R; GRAPH OUT(); cout « "CORR THRESH \n"; cin »CORR THRESH; // ================ GRAPHICS START [.(GRAPHICS START(&vc,GRAPHMODE)) GRAPH_OUT(-1); //================= return R; } int get number 4J(FILE * f) // INITIALISATION GRAPHICMODE, GET SCALE { fscanf(f," %lf ",&CORR_THRESH); return 1 ; } /========================================================= Λint picturejnf_num_new(char *name,SCR_PNT *vertexes, short n) {int ij; char new_str[80]; FILE * datfp; 0; r=fscanf(datfp," %[ Λ \n]s ",new_str); if(_ scsymf( (int)new_str[0]))//FILE INFORMATION ) //(letter or underscore) {sscanf(new_str," %s %s %s %s ",&FILE_name, &FRAME_Name, &STRING_name, &SIGN_name); r=fscanf(datfp," %[ Λ \n]s ",new_str); } for(j=0;j<n+1 ;j++) for(i=0;i<4;i++) (if(FLG) if(fscanf(datfp," %[ Λ \n]s",new_str)==EOF) 3-3,1 {fclose (datfp); return 0;} FLG=1; sscanf(new str," %d %d",&(vertexes[i].c),&(vertexes[i].r)); } fclose(datfp); return 1; ^================================================= _S.9^ #include <io.h> #include <iostream.h> #include <fstream.h> #include "prt_anls.h" #include "PIC_PRO.h" extern const short MaxHistSize; extern const short MaxNumOfWin; extern short Hist[][HistDim]; #defιne Histogramm(i.x) (Hist[(i)][(short)( 0.5*((x)+1) * (HistDim-1)+0.5)]++) void HistCollect( short NOfWin.short St,short Fin.PRT &Db) {short I j; double val; for (i=0;i<NOfWin;i++) for(j=St;j<Fin;j++) { val=Db.CorrValue(ij); Histogramm(i,val); } } ======================================================== RSLT LineEstimation(short TagSize, PRT &Db,short NOfWin.short WSize.double Thr) {RSLT out={0,-1 , 0.0}; short i,j.EndPosDb=0,k; double * DMF=new double[k=Db.s_cols+TagSize]; for (i=0;i<k;DMF[i++]=0.0); double val; for (i=0;i<NOfWin;i++) forO=0;j<Db.s cols;j++) { val=Db.CorrValue(i,j); if (val>Thr) {EndPosDb=i * WSize-j+Db.s_cols; DMF[EndPosDb]+=val; out.n++; } } if(out.n) for(i=0:i<k;i++) if(out.value<DMF[i]) {out.value=DMF[i]; out.pos=i; } delete DMF; ^3 return out; } //=======: int Linelnf(const PRT &P, PRT T.short rw.short Xpos.struct _videoconfιg vc) {SCR_PNT PR(10,10),TG(0,1δ); char mess[δO]="ϋneNum [<0] UnKnown"; int out=UnKnown ; TG.c=Xpos; _settextposition(rw,1 ); *((PCT *)&T)= sign_storage_rgb((const char * )(T.PathName),vc); if (T.s_cols) {_setcolor( color_num(0,0,0)); _rectangle( _GFILLINTERIOR,0,0, 660,60 ); sign_present_RGB(P,PR); sign_present_RGB(T,TG); T.free_PCT(); _setcolor( color_num(240 τ 240,240)); _outtext (mess); cin»out; } else { sprintf(mess,"%s from %s RGB UNAGCESIBLE ", (const char * )(P.SIGN_name), (const char *)(T.STRING_name)); _puttext (mess); } return out; } //========================================================== double CorVal( PRT SP.short WNum.short y) {double v1 ; if(y<0) v1=P.CorrValue(WNum,0); else {if(y>=P.s_cols) v1=P.CorrValue(WNum,P.s_cols-1); else v1=P.CorrValue(WNum,(short)y); } return v1 ; } / ========================================================== #define VALUE(X) ((X)<(P.s_cols-WSize))?CorVal(P, WNum, (X)):CorVal(P, WNum, (X-1)) //========================================================== double Linlnter( PRT SP.short WNum.short WSize .double Pt) {double y1 ,yO,x=WNum * WSize+Pt; short x1,x0; xO=(short)x; x1=(x0>x)?x0-1 :x0+1; y1=CorVal(P, WNum, x1); yO=CorVal( P, WNum, xO); return( y0+(x-x0)*(y1 -y0)/(x1 -xO)); } //================================================= void HistThresh(short *H,short *BotThr.short TopThr.short num) {short S=0; *BotThr=0; TopThr=HistDim-1; while((S+=H[(TopThr)-])<num); S=0; while((S+=H[( * BotThr)++])<num); } //============================================== CString MakeName(CString N) { short k=(N.Spanlncluding(" \t")).GetLength(); char *ρ,fp[60]; p=((char * )(const char *)N)+k; CString M=p; if(M.Find(':')<0) {if(M.GetAt(0)==ΛY) { M=':'+M; M= (char)Lgetdrive( )-1+'A')+M; } else M= fullpath(fp, (const char *)M,80); } M.MakeLower(); return M; } //================================================== CString MakeName(char * p ) {CString M(p); return (MakeName(M)); } /================================================== 5t35 ORIGIN = PWB ORIGIN_VER = 2.1.49 PROJ = TRACK PROJFILE = TRACK.MAK DEBUG = 1 NMAKEBSC1 = set NMAKEBSC2 = nmake CC = cl CFLAGS 3 = /AL /W2 /G2 /GA /DMSC /DMFG_ /DWIN /DPAS /DDLL /GEf IZp /BATCH\ /FR$*.sbr CFLAGS.D = If- /Od /FPi87 /Zi /Gs CFLAGS_R = f- /Os /Og /Oe /FPi87 /Gs CXX = cl CXXFLAGS_G = /G2 /W2 /GA /GEf /Zp /BATCH /FR$ * .sbr CXXFLAGS_D = /f /Zi /Od /Gs CXXFLAGS_R = /f- /Oe /Og /Os /Gs MAPFILE J) = NUL MAPFILE_R = NUL LFLAGSJ3 = /STACK.16000 /BATCH /ONERROR:NOEXE LFLAGS.D = /CO /NOF LFLAGS_R = /NOF LLIBS_G = c:\c700\windev\lib\LIBW.LIB c:\c700\windev\lib\commdlg.lib\ c:\visnplus\lib\win_ai.lib c:\visnplus\lib\mfgmm.lib\ c:\visnplus\lib\iffdll.lib LINKER = link ILINK = iiink LRF = echo > NUL ILFLAGS = /a /e RC = rc -K LLIBS_R = /NOD:LLIBC7 LLIBC7W LLIBS_D = LLIBCEW /NOD:LLIBC7 BRFLAGS = /o $(PROJ).bsc BSCMAKE = bscmake SBRPACK = sbrpack BROWSE = 1 PACK_SBRS = 1 FILES = BITMAP.C MIN_MAG.C PERSP.C TRACK.C TRACK.DEF TRACK.RC LIB.C LINES.C\ QRSOLV.C DEF_FILE = TRACK.DEF OBJS = BITMAP.obj MIN_MAG.obj PERSP.obj TRACK-obj LIB.obj LINES.objΛ QRSOLV.obj RESS = TRACK.res SBRS = BITMAP.sbr MINJv/lAG.sbr PERSP.sbr TRACftsbr LIB.sbr LINES.sbrt QRSOLV.sbr all: $(PR0J).exe .SUFFIXES: .SUFFIXES: .SUFFIXES: .obj .sbr .res .c .re BITMAP.obj : BITMAP.C const.h bitmap.h lines.h track.h min_mag.h lib.h UF $(DEBUG) @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGSJD) /FoBITMAP.obj BITMAP.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /FoBITMAP.obj BITMAP.C « IENDIF BITMAP.sbr : BITMAP.C const.h bitmap.h lines.h track.h min_mag.h lib.h IIF $(DEBUG) @S(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGSJD) /FRBITMAP.sbr BITMAP.C « 2XR1 IELSE @S(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRBITMAP.sbr BITMAP.C « IENDIF MIN_MAG.obj : MIN_MAG.C const-h bitmap.h lines.h track.h persp.h min_mag.h\ lib.h IIF $(DEBUG) @S(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_D) /FoMINJ/IAG.obj MIN_MAG.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /FoMINJ/IAG.obj MINJΛAG.C « IENDIF MIN_MAG.sbr : MIN_MAG.C consLh bitmap.h lines.h track.h persp.h minjTiag.h. lib.h IIF $(DEBUG) @S(CC) @«$(PROJ).rsp Zs $(CFLAGS_G) $(CFLAGS_D) /FRMIN_MAG.sbr MIN.MAG.C « IELSE @S(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRMIN_MAG.sbr MIN_MAG.C « 1ENDIF 5.^3 PERSP.obj : PERSP.C const.h bitmap.h lines.h trac h persp.h min_mag.h lib.h !IF $(DEBUG) @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_D) /FoPERSP.obj PERSP.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGSJ3) $(CFLAGS_R) /FoPERSP.obj PERSP.C « IENDIF PERSP.sbr : PERSP.C consLh bitmap.h lines.h track.h persp.h min nag.h lib.h IIF $(DEBUG) @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_D) /FRPERSP.sbr PERSP.C « IELSE @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRPERSP.sbr PERSP.C « IENDIF TRACKobj : TRACK.C consLh bitmap.h persp.h lines.h track.h min nag.h lib.h !IF $(DEBUG) @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_D) /FoTRACKobj TRACK.C « 1ELSE @S(CC) @«$(PROJ).rsp /c $(CFLAGS_G) a c ) $(CFLAGS_R) /FoTRAC obj TRACKC « 1ENDIF TRACKsbr : TRACK.C const.h bitmap.h persp.h lines.h track.h min_mag.h lib.h !IF $(DEBUG) @$(CC) @«$(PROJ).rsp Zs $(CFLAGS_G) $(CFLAGS_D) /FRTRACKsbr TRACKC « IELSE @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRTRACKsbr TRACKC « IENDIF TRACKres : TRACK.RC track.h frames.dlg $(RC) $(RCFLAGS1 ) IT /fo TRACKres TRAC RC LIB.obj : LIB.C consLh bitmap.h persp.h lines.h track... min_mag.h lib.h IIF $(DEBUG) @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_D) /FoLIB.obj LIB.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /FoLIB.obj LIB.C « IENDIF • LIB.sbr : LIB.C const.h bitmap.h persp.h lines.h track.h rnin_mag.h lib.h IIF $(DEBUG) @$(CC) @«$(PROJ).rsp Zs $(CFLAGS_G) 31. $(CFLAGS_D) /FRLIB.sbr LIB.C « IELSE @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRLIB.sbr LIB.C « IENDIF LINES.obj : LINES.C consLh bitmap.h persp.h lines.h track... min_mag.h lib.h !IF $(DEBUG) @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_D) /FoLINES.obj LINES.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /FoLINES.obj LINES.C « IENDIF LINES.sbr : LINES.C consLh bitmap.h persp.h lines.h track.h min_mag.h lib.h IIF $(DEBUG) @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_D) /FRLINES.sbr LINES.C « IELSE @S(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FRLINES.sbr LINES.C « IENDIF QRSOLV.obj : QRSOLV.C qrsolv.h IIF $(DEBUG) @S(CC) @«$(PROJ).rsp 331 /c $(CFLAGS_G) $(CFLAGS_D) /FoQRSOLV.obj QRSOLV.C « IELSE @$(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /FoQRSOLV.obj QRSOLV.C « 1ENDIF QRSOLV.sbr : QRSOLV.C qrsolv.h !IF $(DEBUG) @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_D) /FRQRSOLV.sbr QRSOLV.C « IELSE @S(CC) @«$(PROJ).rsp Zs $(CFLAGS_G) $(CFLAGS_R) /FRQRSOLV.sbr QRSOLV.C « IENDIF $(PROJ).bsc : $(SBRS) $(BSCMAKE) @« $(BRFLAGS) $(SBRS) « $(PROJ).exe : $(DEF_FILE) $(OBJS) $(RESS) -S(NMAKEBSCI) MAKEFLAGS= -$(NMAKEBSC2) $(NMFLAGS) -f $(PROJFILE) $(PROJ).bsc IIF $(DEBUG) $(LRF) @«$(PR0J).lrf $(RT_OBJS: = + Λ ) $(OBJS: = + Λ ) $@ $(MAPFILE_D) $(LIBS: = + Λ ) + $(LLIBS_G: = + Λ ) + $(LLIBS_D: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_D); « IELSE $(LRF) @«$(PROJ).lrf $(RT_OBJS: = + Λ ) $(OBJS: = + Λ ) $@ $(MAPFILE_R) $(LIBS: = + ) + $(LLIBS_G: = + Λ ) + $(LLIBS_R: = + Λ ) $(DEF_FILE) $(LFLAGS_G) $(LFLAGS_R); « IENDIF $(LINKER) @$(PROJ).lrf $(RC) $(RCFLAGS2) $(RESS) $@ .c.obj : !IF $(DEBUG) @$(CC) @«$(PR0J).rsp /c $(CFLAGS_G) $(CFLAGS_D) /Fo$@ $< « IELSE @S(CC) @«$(PROJ).rsp /c $(CFLAGS_G) $(CFLAGS_R) /Fo$@ $< « lENDIF .c.sbr : IIF $(DEBUG) @$(CC) @«$(PROJ).rsp Zs $(CFLAGS_G) $(CFLAGS_D) /FR$@ $< « IELSE @$(CC) @«$(PROJ).rsp /Zs $(CFLAGS_G) $(CFLAGS_R) /FR$@ $< « lENDIF .re. res : $(RC) $(RCFLAGS1) /r fo $@ $< run: $(PROJ).exe WX $(WXFLAGS) $(PROJ).exe $(RUNFLAGS) debug: $(PROJ).exe WX/p $(WXFLAGS) CVW $(CVFLAGS) $(PROJ).exe $(RUNFLAGS) 53 NAME TRANSFORM DESCRIPTION 'Changing signs' EXETYPE WINDOWS STUB 'WINSTUB.EXE' CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD MOVEABLE MULTIPLE HEAPSIZE 1024 STACKSIZE 8192 ass #include <windows.h> #include "track.h" #include "frames.dlg" trans MENU { POPUP "File" { MENUITEM "Open...", IDMJDPEN MENUrTEM "Write...", IDM WRITE } POPUP "&Pick sign" { MENUITEM "SOriginal", IDM_PICK_ORIG MENUITEM "&Substitue", IDM_PICK_SUBST MENUITEM "&Load Orig", IDM_LOAD_ORIG MENUITEM "&Pick Comers", IDM_PICK_CORNERS } MENUITEM "&change sign", IDM CHANGE POPUP "&Method" { MENUITEM "&Bilinear", IDM_BILINEΞAR MENUITEM "S-Trilinear", IDM_TRILINEAR MENUITEM "&SplitMode", IDM_SPLIT } MENUITEM "&lnfo", IDM INFO POPUP "&MFG" { MENUITEM "&lnit" DISPJNIT MENUITEM "&Grab" DISP_GRAB MENUITEM "&Snap" DISP_SNAP MENUITEM "&Load Pict" DISPJ-OAD MENUITEM "&Load Field" DISP_LOAD_FIELD MENUITEM "&Draw" DISP_DRAW a 3b MENUITEM "&Clean" DISP_CLEAN MENUITEM "&Wipe" DISP_WIPE } MENU ITEM "&Start track", IDM_START TRAC K MENUITEM "&Tracking", IDM_AUTO_TRACK POPUP "&V-Disk" { MENUfTEM "&lnit", SONYJNIT MENUITEM "&Go to", SONY_FRAME MENUITEM "&Replace", SONY_RECORD MENUITEM "&Close", SONY_END } } 331 frames DIALOG 19, 22, 26, 57 STYLE DS /IODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION WS_SYSMENU CAPTION "Edit Frames" FONT 8, "MS Sans Serif BEGIN LTEXT "From Frame", 101 , 10.4, 46, 8 LTEXT To Frame". 102, 10. 22. 56. 8 EDΠTEXT 103.67. . 45. 13, ES_AUTOHSCROLL EDITTEXT 104, 67, 21 , 45, 14, ES_AUTOHSCROLL PUSHBUTTON "OK", 105, 7, 39, 40, 14 PUSHBUTTON "Cancel", 106. 72, 3δ, 40, 14 END long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ; DWORD GetDiblnfoHeaderSize (BYTE huge * ) ; int PASCAL GetDibWidth (BYTE huge * ) ; int PASCAL GetDibHeight (BYTE huge * ) ; BYTE huge * GetDibBitsAddr (BYTE huge * ) ; DWORD GetDrawTableSize(BYTE huge * ) ; BYTE huge * ReadDib (HWND ,char * ,int * ,int * ) ; int PASCAL displayJnformation(HWND ) ; int PASCAL teach_grey_paIlete(HWND , int ) ; BYTE huge * ReadRGB(HWND ,char * ,int*,int*) ; int PASCAL draw_rgb_picture(HWND ,HDC) ; int PASCAL teach gb_pallete(HWND) ; int PASCAL get Jilejype_by_name(char * ) ; int PASCAL create_poly_src_dst() ; int PASCAL keep_subst(HWND,MYBITMAP*) ; BYTE PASCAL get_paletteJndex(BYTE , BYTE , BYTE ) ; int PASCAL WriteGreyRgb (HWND hwnd.char *szFileName,MYBITMAP * Bmap) ; int PASCAL getjn_seriesjlag() ; int PASCAL smooth_ alues(double , double * ,double * ,int,double * ) ; int PASCAL enlarge_area_of_noise(MYBITMAP *,MYB1TMAP *) ; #define GREY_MODEL 1 #define COLOR_MODEL 2 #define RGBA_MODEL 3 #define IN_BILINEAR 2 #define IN TRILINEAR 3 #define FILE_IS_BMP 1 #define FILE_IS_RGB 2 #define FILEJSJJNKNOWN 3 #define AF ZOOM 102 #define PER_WIDTH 103 #define PER_HEIGHT 104 #defιne PER OM OP 107 #define PER_FROM_B0TTOM 108 #defιne PER_OK 109 #define PER_CANCEL 110 #define lDM_OPEN 100 #define IDM_PICK 101 #defιne IDM_CHANGE 104 #define IDM_PERSPECTIVE 102 #define IDMJNFO 103 #define IDM_WRITE 105 #defιne IDM_PICK_ORIG 106 #define IDM_PICK_SUBST 107 #defιne IDM_LOADJDRIG 108 #define !DM_PICK_CORNERS 109 #defιne IDM_NEAREST 110 #define IDM_BILINEAR 111 #define IDM_TRILINEAR 112 #define IDM_SPLIT 114 #defιne IDM_START_TRACK 150 #define IDM_AUTO_TRACK 151 #defιne DISP_SNAP 200 #define DISP_GRAB 201 #define DISP_LOAD 202 #define DISPJDRAW 203 #define DISP_CLEAN 204 #define DISP_WIPE 205 #define DISPJNIT 206 #define DISP_LOAD_FIELD 207 #define lDM DEBUG 300 #defιne SONY_HEADER 400 #defιne SONY.FRAME 401 #define SONY_RECORD 402 #defιne SONYJNIT 403 #define SONY_END 404 #defιne SONY_FROM_FR 103 #defιne SONY_TO_FR 104 #defιne SONYJDK 105 #defιne SONY_CANCEL 106 typedef struct phdr { int cols, rows ; int bp ; } PHDR : typedef BYTE TRIPLE[3] ; typedef struct edge { double xs, ys; double xe, ye; int vertical; LINE I; } EDGE; typedef struct shift { double dx, dy; double sim; /* minimal value of sum of abs. diff. (MAD) maximal value of correlation (COR) * / } SHIFT; typedef struct sign { MYBITMAP * Bmap ; MYBITMAP *BmapGrey ; TRACK_POINTS TrPoints ; } SIGN : a^t #include<math.h> #include<stdio.h> typedef unsigned char byte; typedef struct { unsigned long r : 8. g : 8, b : 8, a : 8; } RGBA; typedef struct { double x ; double y ; } RPOINT ; typedef struct { byte r, g, b; } MYRGB; typedef enum { Grey, Rgb, Rgba } BMTYPE; typedef struct { int cols, rows; BMTYPE typ; BYTE huge *gpic ; } MYBITMAP; typedef double LUMARR[7J[7] . #define B.TMAP_PLACE(bm,i,j) \ *((BYTE huge*)((bm->gpic)+(DWORD)(i)*(DWORD)(bm- >cols)+(DWORD)G))) #define B.TMAP_PLACE_PTR(bm,i.j) \ (BYTE huge * )((bm->gpic)+(DWORD)(i) * (DWORD)(bm->cols)+(DW0RD)ϋ)) #defιne BITMAP_RGBJ ) LACE(bm,i 1 j) \ *((BYTE huge*)((bm->gpic)+((DWORD)(i)*(DWORD)(bm- >cols)+(DWORD)ϋ)) * (DWORD)3)) #defιne BrTMAP_RGB_Pl_ACE_PTR(bm,i,j) \ (BYTE huge*)((bm->gpic)+ ((DWORD)(i) * (DWORD)(bm- >cols)+(DWORD)G))*(DWORD)3) #defιne MIN(a, b) ((a) < (b) ? (a) : (b)) #defιne MAX(a, b) ((a) > (b) ? (a) : (b)) #define DLVLS 3 #defιne ILVLS 1 #define MAX_NO_OFJ " R_WIN 30 typedef struct { double x, y; } PNT; typedef struct { double Af[3][3]; double Ab[3][3]; } Affine_Transform; typedef struct { double Pf[3][3]; double Pb[3][3]; } Perspective_Transform; typedef struct track_points { POINT TrackP[NUM_OF_TRACK_POINTS] ; int NumOfPoints ; } TRACK_POINTS ; typedef struct shift_points { RPOINT TrackP[NUM_OF_TRACK_POINTS] ; 3^3 int NumOfPoints ; } SHIFT JOINTS ; typedef struct tr_win { RPOINT Center ; double Xdir ; double Ydir ; } TR_WIN ; MYBITMAP FAR* brτ_alloc(int , int , BMTYPE ) ; double PASCAL bilinear(double , double , MYBITMAP FAR * ) ; double PASCAL bilinear_red(double , double , MYBITMAP FAR * ) ; double PASCAL bilinear_green(double , double , MYBITMAP FAR *) ; double PASCAL bilinear >lue(double , double , MYBITMAP FAR *) ; int PASCAL multmat(HWND,int , int , int , double * , double *, double *); double PASCAL resampleJrilinear(MYBITMAP FAR* .double.double.double.int) ; double PASCAL resampleJri!inear_red(MYBITMAP FAR * .double, double,double,int) ; double PASCAL resampleJrilinear_blue(MYBITMAP FAR* ,double,double, double, int) ; double PASCAL resampleJriIinear_green(MYBITMAP FAR* .double.double.double.int) ; int PASCAL build_pyramid(HWND,MYBITMAP FAR * ) ; int PASCAL bmJree(MYBITMAP FAR * ) ; int PASCAL createJum_bmap(MYBITMAP * , MYBITMAP ** ) ; int PASCAL duplicate J)map(MYBITMAP * , MYBITMAP " int ) ; int PASCAL create_grey_bounded_bitmap(RECT, MYBITMAP *,MYBITMAP ") ; int PASCAL substractJ.itmaps(RECT,MYB.TMAP * ,MYBITMAP * ,MYBITMAP ** ) ; int PASCAL insert_grey_bounded_bitmap(RECT .MYBITMAP *, MYBITMAP *) ; int PASCAL get_mask_bitmap(HWND,MYBITMAP * ,int .MYBITMAP **) ; int PASCAL fιnd_horizJine(MYBITMAP * .POINT , POINT , RPOINT *) ; int PASCAL fιnd_verticJine(MYBITMAP * ,POINT , POINT , RPOINT *) ; double PASCAL bilinear_rgb(double, double , MYBITMAP FAR* .double *) ; int PASCAL copy_grey_rertJromJrame(MYBITMAP *. MYBITMAP *,RECT ) int PASCAL build_alpha_map(MYBITMAP * * , MYBITMAP * ,RPOINT *) ; int PASCAL split_bitmap(MYBITMAP *,int, int ) ; int PASCAL split_bitmapJrame(MYBITMAP * ,MYBITMAP **, MYBITMAP **) ; int PASCAL sum_grey_bitmap_value(MYBITMAP *,DWORD *) ; int PASCAL filter_noises_by_rects(MYBITMAP * ,RECT ,int , int .MYBITMAP *) ; SW5 #define VALUE_IN(array,i,j,cols) *(arra +(DWORD)(i) * (DWORD)(cols) +0)) #defιne X_DIM 1 #defιne Y DIM 2 int PASCAL l_cpJnt_arrJo_RPOINT(RPOINT * . int * , int * ,int ); int PASCAL l_quadJn_new_origin(RPOINT *,RPOINT * ,int ,int ,int ) ; int PASCAL find_extrenr.es Jn_1dim(RP0INT * , iπt , int .double *, double *); int PASCAL find_best_cluster(HWND, int,RPOINT * ,RPOINT * .int * ,int,int*,int*. RPOINT*.int*); Int PASCAL l_copy_RPOINT_array(RPOINT *.RPOINT *,int ) ; int PASCAL l_copy_int_array(int *,int *,int ) ; int PASCAL l_find_bound_rect(RPOINT *, RECT *) ; int PASCAL print Jransform(HFILE ,char * ,Perspective_Transform *) ; int PASCAL insert_new_vertexes(RPOINT *CurrVert, RPOINT *Vert1 , RPOINT * Vert2, RPOINT * Vert3, RPOINT *Vert4,double * WheighLint num.RPOINT *NewVert) ; int PASCAL transform_rpoint_arr(RPOINT *,RPOINT * ,int,Perspective_Transform) ; 3 6 #defιne FAC 16 #defιne LOBES 2 #defιne FSIZE (LOBES * FAC) #defιne CORRJΛ INDOWX 8 #defιne CORR_WINDOWY 6 MYBITMAP FAR * minrfy(HWND, MYBITMAP FAR * , int) ; int PASCAL sincjilter(int) ; MYBITMAP FAR *hminify(HWND, MYBITMAP FAR * , int); MYBITMAP FAR *vminify(HWND, MYBITMAP FAR * , int ) ; int PASCAL lpf1D(BYTE huge* , int, int, BYTE huge *) ; int PASCAL Ipf 1 D_rgb(BYTE huge* , int, int, BYTE huge * ) ; int PASCAL edge_refιne(MYBITMAP * ,EDGE *,int) ; int PASCAL h_refιne(MYBITMAP * , double * , double *,int) ; int PASCAL v_refine(MYBITMAP *,double *, double *,int) ; int PASCAL sub_pixeMnterp(double, double, double, double *, double *em) ; int PASCAL xysolve(HWND,MYBITMAP * ,MYBITMAP *,SHIFT *,TR_WIN *, int, TRACK_POINTS * . TRACK_POINTS * ,Perspective_Transform * ,HFILE, TRACK_POINTS * ,RPOINT*) ; int PASCAL xysrch(HWND,MYBITMAP * ,MYBITMAP *, SHIFT *,POINT,POINT, int.int.int.int); int PASCAL sub_p_xel_refine(int , int , int.int.SHIFT * ) ; int PASCAL fιnd_average_shift(HWND,int .SHIFT * ,SHIFT_POINTS,SHIFT_POINTS, Perspective_Transform * ) ; int PASCAL Quad2Quad(HWND .RPOINT srcpnts[4],RPOINT dstpnts[4], Perspective_Transform * ) ; int PASCAL copyJransform(Perspective_Transform * ,Perspective_Transform *) ; int PASCAL Thin_Perspective(HWND , SHIFT_POINTS , SHIFT_POINTS ,int, Al Perspective_Transform *) ; int PASCAL trans__greyJrameJoJields(HWND .RPOINT * ,RPOINT MYBITMAP *,RPOINT *, MYBITMAP ** ,MYBITMAP **) ; 3** #define det2(a11 , a12. a21 , a22) (a11 * a22 - a12 * a21 ) int PASCAL perspective(HWND,MYBITMAP FAR * ,MYBITMAP FAR*,RPOINT*,RPOINT * ,int, ^ Perspective_Transform* ) ; int PASCAL Rectan2Quad(HWND,RP0INT * , RPOINT *,Perspective_Transform * ) ; int PASCAL Perspective_map(MYBITMAP FAR*,Perspective_Transform * , MYBITMAP FAR * , RPOINT * ,int) ; RPOINT bPersρective(RPOINT, Perspective_Transform * ) ; RPOINT PASCAL dPerspective(RPOINT , Perspective_Transform * ) ; int PASCAL check_if_rect(RPOINT * ) ; RPOINT PASCAL fPerspective(RPOINT ,Perspective_Transform *) ; int PASCAL median Jilter_5(HWND,MYBITMAP *) ; int PASCAL getJreshJor_occ(MYBITMAP *,int *) ; int PASCAL perspective_mask(HWND .MYBITMAP 'MYBITMAP *, MYBITMAP *, RPOINT *, RPOINT *, int ,int .MYBITMAP *); int PASCAL Perspective_map_mask(MYBITMAP FAR * ,Perspective_Transform* , MYBITMAP FAR *, MYBITMAP * ,RPOINT *,int ,int .MYBITMAP *) ; int PASCAL Quad2Rectan(HWND , RPOINT *, RPOINT *,Perspective_Transform *); int PASCAL perspective_al(HWND .MYBITMAP FAR * ,MYBITMAP FAR * ,MYBITMAP *. RPOINT * .RPOINT * ,int ,Perspective_Transform *) ; int PASCAL Perspective_map__al(MYBITMAP *,Perspective_Transform *, MYBITMAP * , MYBITMAP *,RPOINT * ,int ) ; int PASCAL Perspective_near_map(MYBITMAP * ,Persρective_Transfor m * . MYBITMAP * , RPOINT *,int ) ; int PASCAL perspective_near(HWND .MYBITMAP *, MYBITMAP *, RPOINT * .RPOINT * ,int ,Perspective_Transform * ) ; #include <windows.h> #include <windowsx.h> #include <commdlg.h> #include <stdiib.h> #include <bios.h> #include "const.h" #include "bitmap.h" #ιhclude "persp.h" #include "lines.h" #include "track.h" #include "min mag.h" #include "lib.h 7, #undef RGB #include <mfghost.h> #define UNTIL_FRAME 420 #defιne UNTIL_PICT 4 nt PASCAL bitmap Jor_display(HWND,HDC,MYBITMAP FAR * ,RECT) ; nt PASCAL draw to screen(MYBITMAP * ,int,int) ; nt PASCAL create ϋsp bmap(MYBITMAP *, MYBITMAP * * ,RECT) ; nt PASCAL pick_sign(HWND , UINT , UINT , LONG ) ; nt PASCAL change_sign(HWND , UINT , UINT , LONG ) ; nt PASCAL addJracking_point(HWND , UINT , UINT , LONG ) ; nt PASCAL change sign by tracking(HWND.int) ; nt PASCAL WriteRgb (HWND ,char * ,MYBITMAP *) ; nt PASCAL create norm bmap(HWND ,MYBITMAP * ,MYBITMAP ** ,RECT) ; nt PASCAL keep_όrig(HWND .MYBITMAP * ) ; nt PASCAL pick_original(HWND, UINT, UINT, LONG) ; nt PASCAL create_mask_bmap(HWND .MYBITMAP * .RPOINT *,RPOINT *,RECT.MYBITMAP ** ) ; int PASCAL WriteGreyRgb (HWND hwnd.char *szFileName,MYBITMAP *Bmap) ; int PASCAL adαjclean points(HWND, UINT , UINT , LONG ) ; BOOL FAR PASCAL .export FramesDlg(HWND ,UINT .UINT .LONG ) ; UINT FAR PASCAL _export TimerProc(HWND, UINT.UINT.LONG) ; nt PASCAL SonySearch(HWND,int , int ) ; nt PASCAL SonyRecord(HWND, int) ; nt PASCAL loadJieldJrom_card(HWND,int) ; nt PASCAL load_pictureJrom_card(HWND) ; nt PASCAL load_pictureJromJile(HWND ,char * ) ; nt PASCAL drawJieldJo_screen(HWND .MYBITMAP Vint ) ; nt PASCAL WriteSign (HWND .char * .SIGN * ) ; nt PASCAL ReadSign(HWND ,char * ,SIGN * ) ; nt PASCAL pick_corners(HWND , UINT , UINT , LONG ) ; nt PASCAL getJittness_of_vertexes(HWND,RECT .MYBITMAP *,RPOINT *,DWORD *) ; int PASCAL replace_sign(HWND, RPOINT * ) ; int PASCAL create_subs_sign(HWND hwnd) ; int PASCAL fill_mask_rect(MYB.TMAP * ) ; int PASCAL ValidateOccRects(MYBITMAP * ) ; int PASCAL copy_into_valid_rects() ; char szAppName [] = 'Trans" ; static BYTE huge * IpRgb ; static BYTE huge * IpGreyRgb ; static BYTE huge * IpPtr ; static BYTE huge * IpRepaint ; static BYTE huge * IpDisplay ; static BYTE huge * IpBits ; PALETTEENTRY FAR "ppalentr ; PALETTEENTRY FAR ppalsys[256] ; BYTE FAR ColorTable[32][32][32] ; HPALETTE glhpal, hpalprev ; LOGPALETTE Igcpal ; RECT GIBound ; WORD gIModelColor = COLOR_MODEL ; char stBufferZoom[50j char stBufferAngle[50] char stBufferWidth[50] int OrgX[8],OrgY[6] ; int SignX[4],SignY[4] ; char stBufferHeight[50] ; char stBufferFrToρ[50] ; char stBufferFrBot[50] ; RPOINT SrcPoly[4], DstPoly[4], KeepPoly[4] ; RPOINT BstDst[4] ; int InterpMode = IN_BILINEAR ; MYBITMAP FAR *SrcBmap=NULL ; MYBITMAP FAR * SrcLumap=NULL ; MYBITMAP FAR * SubstBmap=NULL ; MYBITMAP FAR * Subs=NULL ; MYBITMAP FAR * Dispmap=NULL ; MYBITMAP FAR * Normap=NULL ; MYBITMAP FAR * MskBmap=NULL ; SIGN OriginSign ; RECT CiientRect ; int IsRgb ; int FileType ; int SubstCols.SubstRows ; int OrigCols.OrigRows ; int CurrP, UnderPicking,UnderChanging,UnderTracking, UnderOrig.UnderComers ; int InClean ; BYTE huge * IpSubst ; BYTE rpixarr[768] ; TRACKJOINTS TrackBase, TrackCurr ; Perspective_Transform BasicTransf; Perspective_Transform ShiftTransf; int CleanX[2] ; int CleanY[2] ; int CleanCount ; static FARP ROC IpfnTimeProc ; . static LONG RecFrame = 20908; static int SearchFrame = 15662 ; int TimeElapsed ; static int PortNumber ; int FromFr; static int ToFr = UNTIL_PICT ; int PictCount = 0 ; int IsOddLine = 0 ; static DWORD Ticks ; int Waslnit = 0; int SplitMode = 0 ; OFSTRUCT of ; HFILE hFile ; int NumberOfField = 0 ; double Vert1[4], Vert2[4], Vert3[4], Vert4[4] ; double VertWeight[] = {2.0,2.0,3.0,3.0} ; static int InSerieMode = 0 ; static int RepiaceFlag = 1 ; int DummyFrames = 0 ; #defιne DYMMIES 0 RECT ValidOccRects[5] ; int NumOfValidOccRects ; RECT OcclusionRects[5] ; int NumOfOccRects ; int PASCAL WinMain (HANDLE hinstance, HANDLE hPrevlnstance, LPSTR IpszCmdLine, int nCmdShow) { HWND hwnd ; MSG msg ; WNDCLASS wndclass ; if (! hPrevlnstance) { wndclass.style = CS.HREDRAW | CS_VREDRAW ; wndclass. IpfnWndProc = WndProc ; wndclass. cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hlnstance = hinstance ; wndclass.hlcon = NULL ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = GetStockObject (WHTTE_BRUSH) ; wndclass. IpszMenuName = szAppName ; wndclass. IpszClassName = szAppName ; RegisterClass (Swndclass) ; } hwnd = CreateWindow (szAppName, 'Transformations", WS_OVERLAPPEDWINDOW, CWJJSEDEFAULT, CW_USEDEFAULT, CW USEDEFAULT, CWJJSEDEFAULT, NUll, NULL, hinstance, NULL) ; ShowWindow (hwnd, nCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; long FAR PASCAL .export WndProc (HWND hwnd, UINT message, UINT wParam, LONG IParam) { static char szFileName [_MAX_PATH], szTitleName __MAX FNAME + _MAX EXT] ; static char * szFllterfl = { "RGB Files ( * .RGB)", " '-.rgb", static OPENFILENAME ofn ; static FARPROC IpfnFramesProc ; static HANDLE hinst ; BYTE huge * PtrRgb ; char DataBuffer[10],lnputBuffer[10] ; DCB deb ; static int kernel[] = { 1 1 1 1.1.1, LU ) ; switch (message) { case WM.CREATE: ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.lpstrFilter = szFilter [0] ; ofn.lpstrFile = szFileName ; ofn.nMaxFile = .MAX_PATH ; ofn.lpstrFileTitle = szTitleName ; ofn.nMaxFileTitle = _MAX_FNAME + _MAX_EXT ; ofn.lpstrDefExt = "bmp" ; hinst = ((LPCREATESTRUCT)IParam)->hlnstance ; IpfnFramesProc = MakeProclnstance((FARPROC)FramesDlg,hinst); IpfnTimeProc = MakeProclnstance((FARPROC)TimerProc,hinst); Igcpal.palNumEntries = 256 ; Igcpal.palVersion = 0x300 ; lgcpal.palPaIEπtry[0].peRed = 0; Igcpal.palPalEntryfOJ.peGreen = 0; Igcpal.palPalEntryfoj.peBlue = 0; Igcpal.palPalEntrylOj.peFlags = PC.NOCOLLAPSE; hFile = OpenFile("map.dif',&of,OF_CREATE | OF.WRITE) ; OriginSign.Bmap = NULL ; OriginSign.BmapGrey = NULL ; return 0 ; case WM.SIZE: cxClient = LOWORD (IParam) ; cyClient = HIWORD (IParam) ; return 0 ; case WM.COMMAND: switch (wParam) { case IDM.OPEN: ofn.ipstrlnitialDir = "c:\\work\\trans"; if (GetOpenFileName (&ofn)) { FileType = get_filejype__by name(szFileName) ; if ( FileType == FILE_IS_RG~B ) { load_picture from_file(hwnd.szFileName) ; lnvau " dateRect (hwnd, NULL, TRUE) ; } } break ; case IDM.WRITE: ofn.lpstrlnitialDir = "c:\\work\\trans"; if (GetOpenFileName (&ofn)) { FileType = get_fileJype_by_name(szFileName) ; if ( FileType == FILE_IS_RGB ) { WriteRgb (hwnd,szFileName,SrcBmap) ; } else { MessageBox (hwnd, "File must be .rgb", szAppName, MBJCONEXCLAMATION | MB.OK) ; } } break ; case IDM PICK.SUBST: if ( SrcBmap == NULL ) { MessageBox (hwnd, "No Source Bitmap", szAppName, MBJCONEXCLAMATION MB_OK) ; break ; } UnderPicking = 1 ; CurrP = 0 ; SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; break ; case IDM.PICK ORIG: if ( SrcBmap == NULL ) { MessageBox (hwnd, "No Source Bitmap", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } UnderOrig = 1 ; CurrP = 0 ; SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; break ; case IDM.PICK.CORNERS: if ( SrcBmap == NULL ) { MessageBox (hwnd, "No Source Bitmap", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } UnderComers = 1 ; CurrP = 0 ; SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; break ; St z. case IDM_LOAD_ORIG: ReadSign( hwnd,"orig.sgn",&OriginSign) ; break ; case IDM.CHANGE: UnderChanging = 1 ; if ( IpSubst == NULL ) { MessageBox (hwnd, "No Model Bitmap", szAppName, MBJCONEXCLAMATION MB.OK) ; break ; } SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; break ; case IDM.BILINEAR: InterpMode = IN.BILINEAR ; break ; case IDM.TRILINEAR: InterpMode = IN.TRILINEAR ; break ; case IDM.SPLIT: SplitMode = 1 - SplitMode ; break ; case IDM.INFO: display.information(hwnd) ; break ; case IDM.START.TRACK: UnderTracking = 1 ; OriginSign.TrPoints.NumOfPoints = 0 ; TrackBase.NumOfPoints = 0 ; TrackCurr.NumOfPoints = 0 ; SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; break ; case IDM.AUTO.TRACK //Ticks = GetTickCount() ; change.sign.by_tracking(hwnd,1) ; //sprintf(DebugString,'Track+Change %ld", // GetTickCount()-Ticks) ; //MessageBox (hwnd, DebugString, // szAppName, MBJCONEXCLAMATION MB.OK) ; break ; case DISP INIT: mfg_loadcnf("") ; mfg_init() ; Waslnit = 1 ; brea ; case DISP.SNAP: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } mfg_setvframe(RGB) ; mfg_dacmode(TRUE_24); mfg_snap(CAMERA,PAGE1 ) ; break ; case DISP.GRAB: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } mfg_setvframe(RGB) ; mfg_dacmode(TRUE_24); mfg_grab(CAMERA,PAGE1 ) ; break ; case DISP.DRAW: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } draw_to_screen(SrcBmap,0,SrcBmap->rows) ; //draw_to_screen(SrcBmap, 120,200) ; break ; case DISP.CLEAN: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } SetCapture(hwnd) ; SetCursor(LoadCursor(NULL, IDC.CROSS)) ; InCiean = 1 ; break ; case DISP.WIPE: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } aS'i mfg_wipe(0) ; InSerieMode = 1 ; //create_subs_sign(hwnd) ; SetTimer(hwnd, 1 ,500, IpfnTimeProc) ; // To Be REMOVED break ; case DISP.LOAD: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } //load_pictureJrom_card(hwnd) ; sprintf(RgbFileName,"ρict%d.rgb",PictCount++) ; WriteRgb (hwnd,RgbFileName,SrcBmap); InvalidateRect (hwnd, NULL, TRUE) ; break ; case DISP.LOAD.FIELD: if ( Waslnit == 0 ) { MessageBox (hwnd, "Need to Initialize MFG", szAppName, MBJCONEXCLAMATION | MB.OK) ; break ; } load.fieldjrom.card(hwnd.θ) ; InvalidateRect (hwnd. NULL, TRUE) ; break ; • case SONY.INIT: PortNumber = OpenComm("COM2",1024,126) ; sρrintf(DebugString,"PortNumber %d",PortNumber) ; MessageBox (hwnd, DebugString, szAppName, MB ICONEXCLAMATION | MB OK) ; k= BuildCommDCB("COM2:1200,n,δ,1",&dcb) ; " k = SetCommState(&dcb) ; break ; case SONY.FRAME: if ( DialogBox(hinst,"frames",hwnd,lpfnFramesProc) ) { sscanf(stBufferWidth,"%d",&FromFr) ; sscanf(stBufferHeight,"%d",&ToFr) ; } //SonySearch(hwnd,FromFr, PortNumber) ; //TimeElapsed = 0 ; //SetTimer(hwnd,1 ,500, IpfnTimeProc) ; brea ; case SONY.RECORD: ReplaceFlag = 1 - ReplaceFlag ; //SonyRecord(hwnd, PortNumber) ; break ; S≤S-L case SONY.END: k = CloseComm(PortNumber) ; break ; } break ; case WM.LBUTTONDOWN: if ( UnderPicking == 1 ) { pick_sign(hwnd,message,wParam, IParam) ; } if ( UnderOrig == 1 ) { pick_original(hwnd,message,wParam, IParam) ; } if ( UnderCorners == 1 ) { pick_corners(hwnd,message,wParam, IParam) ; } if ( UnderChanging == 1 ) { change sign(hwnd, message, wParam, IParam) ; } ' if ( UnderTracking == 1 ) { add_tracking_point(hwnd,message,wParam,IParam) ; } if ( InClean == 1 ) { add clean points(hwnd,message,wParam,IParam) ; } return 0 ; case WM.RBUTTONDOWN: " rf ( UnderTracking == .1 ) { SetCursor(LoadCursor(NULL,IDC_ARROW)) ; ReleaseCapture() ; UnderTracking = 0 ; create_Ium.bmap(OriginSign.Bmap, &(OriginSign.BmapGrey)) ; WriteSign(hwnd,"orig.sgn",&OriginSign) ; } return 0 ; case WM.MOUSEMOVE: if ( UnderPicking == 1 || UnderChanging == 1 || UnderOrig = 1 ) { sprintf(DebugString,"%d,%d",LOWORD(IParam),HIWORD(IParam)) ; recp.left = recp.top = 400 ; recp.bottom = 420 ; recp. right = 4δ0 ; lnvalidateRect(hwnd,&recp,TRUE) ; } return 0 ; case WM.PAINT: if ( InSerieMode == 1 ) { hdc = BeginPaint (hwnd, &ps) ; EndPaint (hwnd, &ps) ; 3&t break ; } hdc = BeginPaint (hwnd, &ps) ; ToValidate = ps.rcPaint ; if ( UnderPicking == 1 || UnderChanging == 1 || UnderOrig == 1) { TextOut(hdc,ToValidate.left,ToValidate.top,DebugString,lstrlen(DebugString)) } else { if ( SrcBmap != NULL ) { glhpal = CreatePalette(&lgcpal) ; if ( glhpal == NULL ) MessageBox (hwnd, "PALLET NOT CREATED", szAppName, MBJCONEXCLAMATION | MB.OK) ; SetPaletteEntries(glhpal,0,256,ppalentr) ; hpalprev = SelectPalette(hdc, glhpal, FALSE) ; RealizePalette(hdc) ; if ( bitmap Jor_display(hwnd, hdc, SrcBmap.ToVaiidate) == 0) { Deleteθbject(glhpal) ; EndPaint (hwnd, &ps) ; return 0 ; } SetStretchBltMode(hdc,COLORONCOLOR) ; SetDIBitsToDevice(hdc,0,0,Dispmap->cols, Dispmap->rows,0,0,0,Dispmap->rows, (LPSTR)(Dispmap->gpic), (LPBITMAPINFO)lpDisplay, DIB.RGB.COLORS) ; Deleteθbject(glhpal) ; } } // End Of Else EndPaint (hwnd, &ps) ; return 0 ; case WM.DESTROY: lclose(hFile) ; ϊf ( lpDisplay != NULL ) { GlobalFreePtr(lpDisplay) ; } bmJree(SrcBmap) ; bm.free(SrcLumap) ; bm.free(Dispmap) ; bm.free(Normap) ; bmJree(SubstBmap) ; bmjree(Subs) ; bm.free(MskBmap) ; KillTimer(hwnd,1) ; PostQuitMessage (0) ; return 0 ; } aw return DefWindowProc (hwnd, message wParam, IParam) ; } int PASCAL teach.grey.pallete(HWND hwnd, int Entries) { int i ; UINT re ; char Debug[100] ; if ( ppalentr != NULL ) { GlobalFreePtr(ppalentr) ; ppalentr = NULL ; } ppalentr = (PALETTEENTRY FAR * ) GlobalAllocPtr (GMEM.MOVEABLE ,Entries * sizeof(RGBQUAD)) ; for ( i = 0 ; i < Entries ; i++ ) { ppalentr[i].peRed = i ; ppalentrfjj.peGreen = i ; ppalentrfjj.peBlue = i ; ppalentr[i].peFlags = PC.NOCOLLAPSE ; } return 1 ; } int PASCAL get.in.series flag() { return InSerieMode ; } int PASCAL display_information(HWND hwnd) { char Debug[100] ; if ( SrcBmap == NULL ) { MessageBox (hwnd, "No Source Bitmap", szAppName, MBJCONEXCLAMATION | MB.OK) ; return 1 ; } sprintf(Debug,"Width =%d Height = %d ", SrcBmap->cols,SrcBmap->rows) ; MessageBox (hwnd, Debug, szAppName, MBJCONEXCLAMATION | MB.OK) ; return 1 ; } BOOL FAR PASCAL _export FramesDlg(HWND hdlg.UINT message.UINT wParam, LONG IParam) { switch ( message ) { case WM.INITDIALOG: return TRUE ; case WM.COMMAND: switch ( wParam) { case SONY_FROM.FR: GetDlgltemText(hdlg,PER_WIDTH,(LPSTR)stBufferWidth,50) ; return TRUE ; break ; case SONY_TO.FR: GetDlgltemText(hdlg,PER_HEIGHT,(LPSTR)stBufferHeight,50) ; return TRUE ; break ; case SONY.OK EndDialog(hdlg.TRUE) ; return TRUE ; break ; case SONY.CANCEL: EndDialog(hdlg. FALSE) ; return TRUE ; break ; } } return FALSE ; } BYTE huge * ReadRGB(HWND hwnd.char * FileName.int *Width,int *Height) { HFILE hFile ; PHDR phdr; DWORD Size ; HDC hdc ; DWORD offset ; DWORD i, j ; BYTE Red.Green.Blue ; HPALETTE hpal ; int ColorFactor ; BYTE huge * PtrRgb ; BYTE huge * IpRead ; int SizeToRead ; int Incr ; if (_1 == (hFile = Jopen (FileName, OF.READ | OF_SHARE_DENY_WRITE))) return NULL ; Jread (hFile, (LPSTR) &phdr, sizeof (PHDR)) ; if ( gIModelColor == GREY.MODEL ) ColorFactor = 1 ; if ( gIModelColor == COLOR.MODEL ) ColorFactor = 3 ; Size = (DWORD)phdr.cols * (DWORD)phdr.rows * (DWORD)ColorFactor ; *Width = phdr.cols ; *Height = phdr.rows ; IpRgb = (BYTE huge * ) GlobalAllocPtr (GMEM.MOVEABLE, Size) ; PtrRgb = IpRgb ; offset = 0 ; SizeToRead = (DWORD)(phdr.cols) * (DWORD)3 ; IpRead = (BYTE huge * ) GlobalAllocPtr (GMEM.MOVEABLE, SizeToRead) ; while ( offset < Size ) { if (gIModelColor == GREY.MODEL) { Jread(hFile,(LPSTR)lpRead,SizeToRead) ; for ( i = 0 ; i < SizeToRead ; i+= 3 ) { * (PtrRgb+offset) = (*(lpRead+i)+*(lpRead+i+1)+ * (lρRead+i+2))/3 ; offset++ ; } } else { // COLOR.MODEL Jread(hFile,(LPSTR)(PtrRgb+offset), SizeToRead) ; offset += SizeToRead ; } } GlobalFreePtr (IpRead) ; if (gIModelColor == GREY.MODEL) { teach_grey_pallete(hwnd, 256) ; } else { teach_rgb_pallete(hwnd) ; } Jclose(hFile) ; return PtrRgb ; } int PASCAL teach_rgb_pallete(HWND hwnd) { int pl.ij.k ; int red, blue, green ; UINT re ; char Debug[100] ; int Scale[6] = {0,64,126,150,192,255} ; int Fine[4] = {32,96,171,224} ; SLb3 E 26 if ( ppalentr != NULL ) { GlobalFreePtr(ppalentr) ; ppalentr = NULL ; } ppalentr = (PALETTEENTRY FAR * ) GlobalAllocPtr (GMEM.MOVEABLE ,256 * sizeof(RGBQUAD)) ; for ( i = 10 ; i < 245 ; .++ ) { ppalentr[i].peRed = i ; ppalentrfij.peGreen = i ; ppalentn j.peBlue = i ; ppalentr[i].peFlags = PC.RESERVED ; } return 1 ; } int PASCAL get file type.by_name(char * FileName) { int i.len ; len = strlen(FileName)-1 ; for ( i = len ; i > 0 ; i- ) { FileNamep] = toupper(FileName[i]) ; if ( FileName[i] « '.' ) { i++ ; break ; } } if ( strcmp(FileName+i,"RGB") == 0 ) return FILE.IS.RGB ; return FILE.ISJJNKNOWN ; } int PASCAL create_poly src.dst() { SrcPoly[0].x = SrcPoly[0].x = 0.0 ; SrcPoly[1].x = SubstBmap->cols ; // SubstCols ; SrcPoly[1].y = 0.0 ; SrcPoly[2].x = SubstBmap->cols ; //SubstCols ; SrcPoly[2].y = SubstBmap->rows ; //SubstRows ; SrcPoly[3].x = 0.0 ; SrcPoly[3].y = SubstBmap->rows ; //SubstRows ; l.cpJnt_arr_to_RPOINT(DstPoly, OrgX, OrgY,4) ; return 1 ; int PASCAL keep_subst(HWND hwnd.MYBITMAP * Bmap) { DWORD i,j ; HFILE hFile ; PHDR phdr ; DWORD Size ; DWORD offset ; DWORD Cols ; BYTE huge * Ptr ; DWORD Width.Adjust ; SubstCols = phdr.cols = abs(OrgX[1] - OrgX[0]) ; SubstRows = phdr.rows = abs(OrgY[2] - OrgY[1]) ; phdr.bp = 3 ; Size = (DWORD)(phdr.cols) * (DWORD)(phdr.rows)*(DWORD)3 ; IpSubst = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; offset = 0 ; Cols = (DWORD)(phdr.cols)*(DWORD)3 ; Ptr = Bmap->gpic ; Width = (DWORD)(SrcBmap->cols)*(DWORD)3 ; Adjust = (DWORD)(OrgX[0]) * (DWORD)3 ; for ( i = 0 ; i < phdr.rows ; i++ ) { for ( j = 0 ; j< Cols ; j++ ) {. • (IpSubst + offset+j) = * (Ptr+ ((DWORD)Width * (DWORD)(OrgY[0]+i)) + Adjust + j) ; } offset += Cols ; } SubstBmap = bm.alloc(SubstCols,SubstRows,gIModelColor); SubstBmap->gpic = IpSubst ; return 1 ; } int PASCAL keep_orig(HWND hwnd.MYBITMAP * Bmap) { DWORD i,j ; HFILE hFile ; PHDR phdr ; DWORD Size ; DWORD offset ; BYTE huge* IpModel ; DWORD Cols ; BYTE huge * Ptr ; DWORD Width.Adjust ; ass HEET RULE 26^ OrigCols = phdr.cols = abs(OrgX[1] - OrgX[0]) ; OrigRows = phdr.rows = abs(OrgY[2] - 0rgY[1]) ; phdr.bp = 24 ; Size = (DWORD)(phdr.cols) * (DWORD)(phdr.rows) * (DWORD)3 ; IpModel = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; offset = 0 ; Cols = (DWORD)(phdr.cols) * (DWORD)3 ; Ptr = Bmap->gpic ; Width = (DWORD)(SrcBmap->cols)*(DWORD)3 ; Adjust = (DWORD)(OrgX[0])*(DWORD)3 ; for ( i = 0 ; i < phdr.rows ; i++ ) { Ptr = Bmap->gpic + ((DWORD)Width * (DWORD)(OrgY[0]+i)) + Adjust ; for ( j = 0 ; j< Cols ; j++ ) { * (lρModel + offset+j) = *(Ptr++) ; } offset += Cols ; } bmJree(OriginSign.Bmap) ; bm.free(OriginSign.BmapGrey) ; OriginSign.Bmap = bm_alloc(OrigCols,OrigRows I glModelColor); OriginSign.Bmap->gpic = IpModel ; WriteRgb (hwnd,"orig.rgb",OriginSign.Bmap); return 1 ; } int PASCAL bitmap Jor_display(HWND hwnd, HDC hdc.MYBITMAP FAR * Bmap,RECT ToValidate) { LONG Size.ij ; BYTE huge * TmpB ; BYTE huge *Tmp ; BYTE huge * Ptr ; char Debug[100] ; GetSystemPaletteEntries(hdc,(UINT)0,(UINT)256,ppalsys) ; Size = 40 +(DWORD)(sizeof(RGBQUAD)) * (DWORD)256 ; if ( IpDisplay != NULL ) { GlobalFreePtr(lpDisplay) ; } IpDisplay = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; IpBits = IpDisplay + 40+(DWORD)(sizeof(RGBQUAD)) * (DWORD)256 ; Ptr = IpDisplay +40 ; E 26^ ((BITMAPINFOHEADER huge * )lpDisplay)->biSize = 40 ; ((BITMAPINFOHEADER huge * )lpDisplay)->biWidth = Bmap->cols ; ((BITMAPINFOHEADER huge * )lpDisplay)->biHeight =Bmap->rows ; ((BITMAPINFOHEADER huge * )lpDisplay)->biPlanes = 1 ; ((BITMAPINFOHEADER huge*)lpDispiay)->biBitCount = 8 ; ((BITMAPINFOHEADER huge*)lpDisplay)->biCompression = 0 ; ((BITMAPINFOHEADER huge * )lpDisplay)->biSizelmage = 0 ; ((BITMAPINFOHEADER huge*)lpDisplay)->biXPelsPerMeter = 0 ; ((BITMAPINFOHEADER huge * )lpDisplay)->biYPelsPerMeter = 0 ; ((BITMAPINFOHEADER huge*)lpDisplay)->biClrUsed = 0 ; ((BITMAPINFOHEADER huge * )lpDisplay)->biClrlmportant = 0 ; for ( i = 0 ; i < 256 ; i++ ) { (BYTE) * (Ptr + (DWORD)(i * sizeof(RGBQUAD))) = ppalsys[i].peBlue; (BYTE) * (Ptr + (DW0RD)(i * sizeof(RGBQUAD)+1 ))= ppalsys[i].peGreen; (BYTE) * (Ptr + (DW0RD)(i * sizeof(RGBQUAD)+2))= ppalsys[i].peRed; (BYTE) * (Ptr + (DWORD)(i * sizeof(RGBQUAD)+3)) = 0 ; } return (create.disp.bmap(Bmap, &Dispmap,ToValidate)) ; } int PASCAL draw_to_screen(MYB!TMAP * Bmap,int FromLine.int ToLine) { int i,j ; BYTE huge *Ptr ; BYTE huge *PtrR ; BYTE huge * PtrG ; BYTE huge * PtrB ; int Cols ; Cols = Bmap->cols ; Ptr = Bmap->gpic ; Ptr += (DWORD)FromLine * (DWORD)Cols*(DWORD)3 ; PtrR = Ptr ; PtrG = Ptr+1 ; PtrB = Ptr+2 ; mfg_setgframe(R); for ( i = FromLine ; i < ToLine ; i++ ) { for (j = 0 ; j < Cols ; j++ ) { ixarrO] = * PtrR ; PtrR += 3 ; } mfg_bwhline(PAGEO,0,i,Cols,rpixarr) ; } mfg_setgframe(G); for ( i = FromLine ; i < ToLine ; i++ ) { for ( j = 0 ; j < Cols ; j++ ) { rpixarrϋ] = * PtrG ; p,rG += 3 : } mfg_bwhiine(PAGEO,0,i,Cols,rpixarr) ; } mfg_setgframe(B); for ( i = FromLine ; i < ToLine ; i++ ) { for ( j = O ; j < Cols ; j++ ) { φixarrQ] = * PtrB ; PtrB += 3 ; ^ } mfg_bwhline(PAGEO,0,i,Cols,φixarr) ; } return 1 ; } int PASCAL create_disp_bmap(MYBITMAP * Bmap, MYBITMAP * *LumBmap,RECT ToValidate) { BYTE huge * Tmp; BYTE huge * TmpB ; int ToPad ; int Cols, Rows ; DWORD Size ; int ij ; long k ; int RowLimit ; if ( Normap == NULL ) return 0 ; Cols = Bmap->cols ; Rows = Bmap->rows ; ToPad = Cols%4 ; if ( ToPad > 0 ) ToPad = 4 - ToPad ; Tmp = Bmap->gpic ; if ( ToValidate.top == 0 ) { if ( * LumBmap != NULL ) bm.free( * LumBmap) ; *LumBmap = bm.alloc(Cols+ToPad,Rows, GREY.MODEL); Size = (DWORD)(Cois+ToPad)*(DWORD)Rows ; (*LumBmap)->gpic = (BYTE huge*)GlobalAllocPtr(GMEM.MOVEABLE,Size) ; } RowLimit = min(Rows,ToValidate.bottom) ; for ( i = RowLimit ; i> ToValidate.top ; i- ) { Tmp = Normap->gpic +(DWORD)(i-1)*(DWORD)Cols ; <_9b$ TmpB = ( * LumBmap)->gpic+(Rows-i) * (DWORD)(Cols+ToPad) ; for ( j = 0 ; j < Cols ; j++ ) { * (TmpB++) = * (Tmρ++) ; } for ( j = 0 ; j < ToPad ; j++ ) { * (TmpB++) = 0 : } } return 1 : } int PASCAL pick_sign(HWND hwnd, UINT message, UINT wParam, LONG IParam) { OrgXfCurrP] = LOWORD(IParam); OrgY[CurrP] = HIWORD(IParam); CurrP++ ; if ( CurrP = 2 ) { OrgX[2] = OrgX[1] ; OrgY[2] = OrgY[1] ; OrgY[1] = OrgY[0] ; OrgX[3] = OrgX[0] ; OrgY[3] = OrgY[2] ; UnderPicking = 0 ; CurrP = 0 ; SetCursor(LoadCursor(NULL,IDC_ARROW)) ; ReleaseCapture() ; keep_subst(hwnd, SrcBmap) ; if ( InteφMode == IN.TR.LINEAR ) build__pyramid(hwnd, SubstBmap) ; } return 1 ; } int PASCAL add_ciean_points(HWND hwnd, UINT message, UINT wParam, LONG IParam) { static int kernelf] = { 1 1 1 1,1 ,1. 1 ,1,1 } ; int gaoi.raoi.baoi ; int DifX,DifY ; CleanX[CleanCount] = LOWORD(IParam); CleanY[CleanCount] = HIWORD(IParam); CleanCount++ ; - . , , ' HEET RULE 26 if ( CleanCount == 2 ) { InClean = 0 ; CleanCount = 0 ; SetCursor(LoadCursor(NULL, IDC.WAIT)) ; DifX = CleanX[1]-CleanX[0] ; DifY = Clean Y[1]-CleanY[0] ; gaoi = mfg.gaoi_fbcreate(G,CleanX[0],CleanY[0],DifX,DifY) ; mfg_median(gaoi,gaoi,3,3,kernel) ; raoi = mfg_gaoi_fbcreate(R,CleanX[0],CleanY[0],DifX,D.fY) ; mfg_median(raoi,raoi,3,3,kernel) ; . baoi = mfg_gaoi.fbcreate(B,CleanX[0],CleanY[0],D_fX,DifY) ; mfg.median(baoi,baoi,3,3,kernel) ; SetCursor(LoadCursor(NULL, IDC.ARROW)) ; ReleaseCapture() ; //SetTimer(hwnd,1 ,40, IpfnTimeProc) ; } return 1 ; } int PASCAL pick_corners(HWND hwnd, UINT message, UINT wParam, LONG IParam) { RPOINT CoefsH1 ,CoefsH2,CoefsV1 ,CoefsV2 ; POINT Point1,Point2 ; char String[100] ; OrgX[CurrP] = LOWORD(IParam); OrgY[CurrP] = HIWORD(IParam); CurrP++ ; if ( CurrP == 4 ) { UnderCorners = 0 ; CurrP = 0 ; SetCursor(LoadCursor(NULL, IDC.ARROW)) ; ReleaseCapture() ; } return 1 ; } int PASCAL pick_original(HWND hwnd, UINT message, UINT wParam, LONG IParam) { RPOINT CoefsH1 ,CoefsH2,CoefsV1,CoefsV2 ; POINT Point1.Po.nt2 ; char String[100] ; OrgX[CurrP] = LOWORD(IParam); ^70 OrgY[CurrP] = HIWORD(IParam); CurrP++ ; if ( CurrP == 2 ) { OrgX[2] = OrgX[1] ; OrgY[2] = OrgY[1j ; OrgY[1] = OrgY[0] ; OrgX[3] = OrgX[0] ; OrgY[3] = OrgY[2j ; UnderOrig = 0 ; CurrP = 0 ; SetCursor(LoadCursor(NULL, IDC_ARROW)) ; ReleaseCapture() ; keep orig(hwnd, SrcBmap) ; } return 1 ; } int PASCAL change_sign(HWND hwnd, UINT message, UINT wParam, LONG IParam) { RECT Bound ; RPOINT PtO,Pt1 ,Pt2,Pt3; POINT Point1 ,Point2 ; RPOINT SrcPnts[4] ; char String[100] ; DWORD FromTime.ToTime ; EDGE Edgel ,Edge2,Edge3,Edge4 ; char DebugString[50] ; MYBITMAP * AlphaMap ; OrgX[CurrP] = LOWORD(IParam); OrgYfCurrP] = HIWORD(IParam); CurrP++ ; if ( CurrP — 4 ) { UnderChanging = 0 ; CurrP = 0 ; SetCursor(LoadCursor(NULL, IDC.ARROW)) ; ReleaseCapture() ; create_poly_src_dst() ; l_find_bound_re " ct(DstPoly, &Bound) ; //create_mask_bmap(hwnd,OriginSign.BmapGrey,SrcPoly,DstPoly,Bound,&M skBmap) ; //Ticks = GetTickCountQ ; build.alpha.map(&AlphaMap, SrcBmap, DstPoly) ; //ρerspective_al(hwnd,SubstBmap,SrcBmap,AlρhaMap,SrcPoly, // DstPoly, gIModelColor, SBasicTransf) ; bm.free(AlphaMap) ; perspective(hwnd, SubstBmap, SrcBmap, SrcPoly , DstPoly, gIModelColor, &BasicTransf) ; //sprintf(DebugString,"Change %ld",GetTickCount()-Ticks) ; //MessageBox (hwnd, DebugString, // szAppName, MBJCONEXCLAMATION | MB.OK) ; //perspective_mask(hwnd,SubstBmap,SrcBmap,SrcPoly, // DstPoly, gIModelColor, InterpMode.MskBmap) ; create_norm_bmap(hwnd,SrcBmap,.8_Normap, Bound) ; InvalidateRect (hwnd, SBound, TRUE) ; } return 1 ; } int PASCAL add_tracking_point(HWND hwnd, UINT message, UINT wParam, LONG IParam) { int Place ; Place = OriginSign.TrPoints.NumOfPoints ; if ( Place >= NUM.OF.TRACK.POINTS ) { MessageBox (hwnd, "Cannot track more than 30 points", szAppName, MBJCONEXCLAMATION | MB.OK) ; SetCursor(LoadCursor(NULL, IDC.ARROW)) ; ReleaseCapture() ; UnderTracking = 0 ; create.lum.bmap(OriginSign.Bmap, &(OriginSign.BmapGrey)) ; WriteSign(hwnd,"orig.sgn",&OriginSign) ; return 1 ; } OriginSign.TrPoints.TrackP[Place].x = LOWORD(IParam); OriginSign.TrPoints.TrackP[Place].y = HIWORD(IParam); TrackBase.TrackP[Place].x = LOWORD(IParam); TrackBase.TrackPfpiacej.y = HIWORD(IParam); TrackCurr.TrackP[Place].x = LOWORD(IParam); TrackCurr.TrackP[Place].y = HIWORD(IParam); OriginSign.TrPoints.NumOfPoints++ ; TrackBase.NumOfPoints++ ; TrackCurr.NumOfPoints++ ; return 1 ; } int PASCAL change.sign.by tracking(HWND hwnd, int ToDispIay) { Perspective.Transform NewTransf ; Perspective Transform Tp ; EET (RULE 26* Perspective.Transform TpCurr ; RECT Bound ; int i,k ; double DiffUp, Diff Down ; double u,v,w ; char String[100] ; int dx,dy ; DWORD Size ; int Cols, Rows ; RPOINT SrcPnts[4] ; RPOINT RPointln.RPointOut ; SHIFT Shift ; SHIFT Shifts[NUM_OF_TRACK_POINTS]; double DstX,DstY ; RECT Rectan ; MYBITMAP * DestBmap ; RPOINT CrnPoly[4] ; TRACK.POINTS ModelPoints ; TRACK.POINTS DBasePoints ; RPOINT DiffArr[MAX NO.OF_TR.WIN] ; MYBITMAP *AlphaMap ; TR.WIN Windows[MAX_NO_OF_TR_WIN] ; //create.subs.sign(hwnd) ; sprintf(String,"\n\n\t\tNew Frame\n") ; _lwrite(hFile,String,strlen(String)) ; l.cp_int_arrJo_RPOINT(SrcPnts, SignX, SignY,4) ; Quad2Quad(hwnd,SrcPnts,DstPoly,&TpCurr) ; IJind_bound_rect(DstPoly, &Rectan) ; Cols = Rectan.right-Rectan.left+1 ; Rows = Rectan. bottom-Rectan.top+1 ; DestBmap = bm alloc(Cols, Rows, GREY.MODEL) ; Size = (DWORD~)Cols*(DWORD)Rows ; DestBmap->gpic = (BYTE huge * )GlobaIAIIocPtr(GMEM MOVEABLE.Size) ; l_quad.in.new_origin(CrnPoly,DstPoly,Rectan.left,Rectan.top,4) ; for ( i = 0 ; i < 4 ; i++ ) { sprintf(String,"%d: Dst %lf,%lf Cm %lf,%lf Src %lf,%lf\n", i,DstPoly[i].x,DstPoly[i].y,CrnPoly[i].x,CrnPoly[i].y, SrcPnts[i].x,SrcPnts[i].y) ; _lwrite(hFile,String,strlen(String)) ; } Quad2Quad(hwnd,SrcPnts, CmPoly,&Tp); 3- $ TrackCurr.NumOfPoints = 0 ; ModelPoints.NumOfPoints = 0; DBasePoints.NumOfPoints = 0 ; for ( i = k= 0 ; i < OriginSign.TrPoints.NumOfPoints ; i++ ) { RPointin.x = (double)OriginSign.TrPoints.TrackP[i].x ; RPointln.y = (double)OriginSign.TrPoints.TrackP[i].y ; RPointOut = fPerspective(RPointln, &Tp) ; if (RPointOuLx <= CORR.WINDOWX || RPointOut.x >= (Cols- CORR.WINDOWX-1) ) continue ; if (RPointOuLy <= CORR.WINDOWY || RPointOuLy >= (Rows- CORR.WINDOWY-1) ) continue ; ModelPoints.Tr ackP[k].x = (int)(RPointOut.x+0.5) ; ModelPoints.TrackP[k].y = (int)(RPointOut.y+0.5) ; if ( Model Points.TrackP[k].x > RPointOut.x ) { // To minus DiffArr DiffArr[k].x = (double)ModelPoints.TrackP[k].x - RPointOuLx ; } else { DiffArr[k].x = RPointOut.x - (double)ModeIPoints.TrackP[k].x ; } if ( ModelPoints.TrackP[k].y > RPointOut.y ) { DiffArr[k].y = (double)ModelPoints.TrackP[k].y - RPointOuLy ; } else { DiffArr[k].y = RPointOut.y - (double)ModelPoints.TrackP[k].y ; } DBasePoints.TrackP[k].x = OriginSign.TrPoints.TrackP[i].x; DBasePoints.TrackP[k].y = OriginSign.TrPoints.TrackP[i].y; RPointOut = fPerspective(RPointln, &TpCurr) ; TrackCurr.TrackP[k]_x = (int)(RPointOut.x+0.5) ; TrackCurr.TrackP[k].y = (int)(RPointOut.y+0.5) ; if ( TrackCurr.TrackP[k].x > RPointOuLx ) { // To minus DiffArr DiffArr[k].x += (double)TrackCurr.TrackP[k].x - RPointOuLx ; } else { DiffArr[k].x += RPointOuLx - (double)TrackCurr.TrackP[k].x ; } if ( TrackCurr.TrackP[k].y > RPointOuLy ) { DiffArr[k].y += (double)TrackCurr.TrackP[k].y - RPointOuLy ; } else { DiffArr[k].y += RPointOuLy - (double)TrackCurτ.TrackP[k].y ; } k++ ; TrackCurr.NumOfPoints++ ; DBasePoints.NumOfPoints++ ; ModelPoints.NumOfPoints++ ; } perspective(hwnd,OriginSign.BmapGrey,DestBmap,SrcPnts, CrnPoly, GREY.MODEL, &BasicTransf) ; xysolve(hwnd,Normap,DestBmap,Shifts,Windows,9,&ModelPoints, &TrackCurr,&NewTransf,hFile,&DBasePoints,DiffArr) ; bmJree(DestBmap) ; forTi = 0 ; i < 4 ; i++ ) { sprintf(String,"Before %d -%lf,%IAn",i,SrcPnts[i].x, SrcPnts[i].y) ; lwrite(hFile, String, strlen(String)) ; //DstX = SrcPnts[i].x * NewTransf.Pf[0][0] + // SrcPnts[i].y * NewTransf.Pf[1][0] + NewTransf.Pf[2][0] //DstY = SrcPnts[i].x * NewTransf.Pf[0][1] + // SrcPnts[i].y * NewTransf.Pf[1][1 ] + NewTransf.Pf[2][1] //w = SrcPnts[i].x * NewTransf.Pf[0][2] + // SrcPnts[i].y * NewTransf.Pf[1][2] + NewTransf.Pf[2][2] DstX = CrnPoly[i].x * NewTransf.Pf[0][0] + CmPoly[i].y * NewTransf.Pf[1][0] + NewTransf.Pf[2][0] DstY = CrnPoly[i].x * NewTransf.Pf[0][1] + CrnPoly[i].y * NewTransf.Pf[1][1] + NewTransf.Pf[2][1] w = CrnPoly[i].x * NewTransf.Pf[0][2] + CrnPoly[i].y * NewTransf.Pf[1][2] + NewTransf.Pf[2][2] DstPoly[i].x = DstX w ; DstPolyjij.y = DstY/ ; sprintf(String;Vertex %d -%lf,%lf\n",i,DstPoly[i].x, DstPoly[i].y) ; Jwrite(hFile,String,strlen(String)) ; } I find_bound_rect(DstPoly, &GIBound) ; Γ OCCLUSION create.mask.bmap(hwnd,OriginSign.BmapGrey,SrcPnts,DstPoly,GIBound,& MskBmap) ; fill.mask.rect(MskBmap) ; ValidateOccRects(MskBmap) ; copy into vaiid_rects() ; */ //Ticks = GetTickCount() ; buiid.alpha.map(&AlphaMap, SrcBmap, DstPoly) ; //WriteGreyRgb (hwnd,"alp.rgb",AlphaMap) ; perspective.al(hwnd,SubstBmap,SrcBmap,AlphaMaρ,SrcPoly, DstPoly, gIModelColor, &BasicTransf) ; //Perspective.map.al(Subs, &NewTransf, SrcBmap, AlphaMap, // " DstPoly.glModelColor); //perspective_mask(hwnd, SubstBmap, SrcBmap, AlphaMap, SrcPoly, //TESTS // DstPoly, gIModelColor, InteφMode.MskBmap) ; //TESTS bmJree(AlphaMap) ; create_norm_bmap(hwnd,SrcBmap,&Normap,GIBound) ; //TESTS if ( ToDispIay == 1 ) { InvalidateRect (hwnd, &GIBound, TRUE) ; } return : £1S int PASCAL WriteRgb (HWND hwnd.char * szFileName,MYBITMAP * Bmap) { PHDR phdr; DWORD ..Offset ; long int Size ; HFILE hFile ; OFSTRUCT IpOpenBuff ; UINT ToWrite ; phdr. cols = Bmap->cois ; phdr.rows = Bmap->rows ; phdr.bp = 24 ; Size = (DWORD)phdr.cols*(DWORD)phdr.rows * (DWORD)3 ; hFile = OpenFile(szFileName,&lpOpenBuff,OF_CREATE | OF.WRITE) ; _lwrite(hFile,&phdr,sizeof(phdr)) ; Offset = 0 ; while ( Size > 0 ) { ToWrite = min(32768ul,Size) ; Jwrite(hFile,Bmap->gpic+Offset,ToWrite) ; Offset += ToWrite ; Size -= ToWrite ; } Jclose(hFile) ; return 1 ; } int PASCAL WriteGreyRgb (HWND hwnd.char *szFileName,MYBITMAP *Bmap) { PHDR phdr; DWORD i.Offset ; long int Size ; HFILE hFile ; OFSTRUCT IpOpenBuff ; UINT ToWrite ; BYTE huge *RgbArr ; BYTE huge *GreyTmp ; BYTE huge * Tmp ; DWORD GreySize ; phdr.cols = Bmap->cols ; phdr.rows = Bmap->rows ; 2.% phdr.bp = 24 ; Size = (DWORD)phdr.cols * (DWORD)phdr.rows * (DWORD)3 ; RgbArr = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; hFile = OpenFile(szFileName,&lpOρenBuff,OF_CREATE | OF.WRITE) ; _lwrite(hFile,&phdr,sizeof(phdr)) ; Tmp = RgbArr ; GreyTmp = Bmap->gpic ; GreySize = (DWORD)phdr.cols * (DWORD)ρhdr.rows ; for ( i = 0 ; i < GreySize ; i++ ) { *(Tmp++) = *( GreyTmp) ; *(Tmp++) = *(GreyTmp) ; * (Tmp++) = * (GreyTmp++) ; } Offset = 0 ; while ( Size > 0 ) { ToWrite = min(32768ul,Size) ; _lwrite(hFile, RgbArr+Offset.ToWrite) ; Offset += ToWrite ; Size -= ToWrite ; } Jclose(hFile) ; GlobalFreePtr(RgbArr) ; return 1 ; } int PASCAL WriteSign (HWND hwnd.char * szFileName,SIGN *Sign) { DWORD i.Number ; HFILE hFile ; OFSTRUCT IpOpenBuff ; char String[100] ; Number = Sign->TrPoints.NumOfPoints ; sprintf(String,"%05d\n",10*Number+9+11 ) ; hFile = OpenFile(szFileName,&lpOpenBuff,OF_CREATE | OF.WRITE) ; _lwrite(hFile,String,strlen(String)) ; Jwrite(hFile,"orig.rgb\n",9) ; sprintf(String,"%05d %05d %05d %05d %05d %05d %05d %05d\n", OrgX[0],OrgY[0],OrgX[1].OrgY[1],OrgX[2],OrgY[2],OrgX[3].OrgY[3]) ; Jwrite(hFile,String,strlen(String)) ; sprintf(String,"%05d\n",Number) ; 9.11 Jwrite(hFile, String, strlen(String)) ; for ( i = 0 ; i < Number ; i++ ) { sprintf(String,"%4d %4d\n",Sign->TrPoints.TrackP[i].x, Sign->TrPoints.TrackP[i].y) ; lwrite(hFile,String,strlen(String)) ; } " Jclose(hFile) ; return 1 ; } int PASCAL ReadSign(HWND hwnd.char * szFiieName,SIGN *Sign) { DWORD i.Number ; HFILE hFile ; OFSTRUCT IpOpenBuff ; char String[100] ; int NumOfBytes ; int NumOfPoints ; int Xval.Yval ; int Width, Height ; BYTE huge * Ptr ; hFile = OpenFile(szFileName,&lpOpenBuff, OF.READ) ; lread(hFile,String,6) ; // Size of bytes in File. String[5] = '\0' ; sscanf(String,"%d",&NumOfBytes) ; lread(hFile,String,9) ; // RGB File Name. ~String[8] = * \0 * ; Ptr = ReadRGB(hwnd,String,&Width,&Height); bm_free(Sign->Bmap) ; Sign->Bmap = bm.alloc(Width,Height,glModelColor); Sign->Bmap->gpic = Ptr ; create_lum.bmap(Sign->Bmap, &(Sign->BmapGrey)) ; / WriteGreyRgb (hwnd,"greyorg.rgb",Sign->BmapGrey) ; lread(hFile,String,48) ; sscanf(String,"%d %d %d %d %d %d %d %d",&(SignX[0]),&(SignY[0]), &(SignX[1]),&(SignY[1]),&(SignX[2]),&(SignY[2]), &(SignX[3]),&(SignY[3])) ; Jread(hFile,String,6) ; // Number of Points. String[5] = '\0' ; sscanf(String,"%d",&NumOfPoints) ; for ( i = 0 ; i < NumOfPoints ; i++ ) { Jread(hFile, String, 10) ; String[9] = '\0' ; sscanf(String,"%d %d".&Xval,&Yval) ; Sign->TrPoints.TrackP[i].x = Xval ; Sign->TrPoints.TrackP[i].y = Yval ; } Sign->TrPoints. NumOfPoints = NumOfPoints ; Jclose(hFile) ; return 1 ; } int PASCAL create_norm_bmap(HWND hwnd.MYBITMAP * Bmap, MYBITMAP **NormBmap, RECT ToValidate) { BYTE huge * TmpNorm ; BYTE huge * Tmp ; int Cols.Rows ; DWORD Size ; long i,j,k ; int RowLimit ; Cols = Bmap->cols ; Rows = Bmap->rows ; if ( ToValidate.top == 0 ) { if ( *NormBmap != NULL ) bm_free( * NormBmap) ; • NormBmap = bm_alloc(Cols, Rows, GREY.MODEL); Size = (DWORD)Cois*(DWORD)Rows ; ( * NormBmap)->gpic = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; } RowLimit = min(Rows,ToValidate.bottom) ; i = ToValidate.top ; Tmp = Bmap->gpic +(DWORD)i * (DWORD)Cols * (DWORD)3 ; TmpNorm = ( * NormBmap)->gpic+ (DWORD)i * (DWORD)Cols ; while ( i < RowLimit ) { for (j = 0 ; j < Cols ; j++ ) { *(TmpNorm++) = (BYTE)((double)(*(Tmp++)) * 0.299 + (double)*(Tmp++)* 0.587 + (double)*(Tmp++) * 0.114); } i++ ; } return 1 ; } a-Η int PASCAL create_mask_bmap(HWND hwnd.MYBITMAP • GreyMdIBmap, RPOINT *SrcPoly, RPOINT "DstPoly.RECT Bound. MYBITMAP **MaskBmap) { MYBITMAP * BoundedBmap =NULL ; MYBITMAP *DiffBmap =NULL; int Tresh ; char String[100] ; DWORD FromTime.ToTime ; DWORD Sum ; //WriteGreyRgb (hwnd,"model. rgb", GreyMdIBmap) ; create_grey.bounded_bitmap(Bound,Normap,&BoundedBmap) ;//Cop the area to // be changed into a //separate bitmap. //WriteGreyRgb (hwnd,"bound0.rgb",BoundedBmap) ; perspective(hwnd, GreyMdIBmap, Normap.SrcPoly, DstPoly, GREY.MODEL, &BasicTransf) ; //perspective.near(hwnd,GreyMdlBmap,Normap,SrcPoly, // DstPoly, GREY.MODEL, &BasicTransf) ; // Perform perspective // grey of the current sign // with itself into NormBmap. substract.bitmaps(Bound,Normap,BoundedBmap,&DiffBmap) ; // Subtract BoundedBmap // from the transformed // sign area in NormBmap. sum_grey_bitrnap_value(DiffBmap,&Sum) ; //sprintf(String."SUm is %ld",Sum) ; / MessageBox (hwnd, String, szAppName, MB ICONEXCLAMATION | MB.OK) ; //WriteGreyRgb (hwnd,"diff.rgb",DiffBmap) ; insert_grey_bounded.bitmap(Bound,BoundedBmap,Nonmap) ; // retrieve original //picture into Normap. median_filter.5(hwnd,DiffBmap) ; // Creates a median // filter on Diffbmap. WriteGreyRgb (hwnd,"diff1.rgb",DiffBmap) ; oβϋ getJresh_for_occ(DiffBmap,&Tresh) ; // Gets the treshold // for occlusion. //sprintf(String,'Tresh Value = %d",Tresh) ; //MessageBox (hwnd, String, szAppName, MBJCONEXCLAMATION | MB_OK) ; get.mask_bitmap(hwnd,DiffBmap,Tresh,MaskBmap) ; WriteGreyRgb (hwnd,"diff2.rgb",*MaskBmap) ; bmJree(BoundedBmap) ; bmJree(DiffBmap) ; return 1 ; } int PASCAL SonySearch(HWND hwnd, int frame, int port) { char str[6]; int i, input; const int N.TRY = 5; char DataBuffer[128] ; char lnputBuffer[128] ; int len ; int ErrCode ; char String[50] ; COMSTAT IpStat ; sprintf(str,"%05d",frame); DataBuffer[0] = 0x43 ; // Search WriteComm(port,DataBuffer, 1); lnputBuffer[0] = 0x00 ; while ( lnputBuffer[0] != OxOA ) { ReadComm(port,lnputBuffer,1) ; ErrCode = GetCommError(port,&IpStat) ; //sprintf(String,"Error Code = %d",ErrCode) ; //MessageBox (hwnd, String, szAppName, MB.ICONEXCLAMATION MB.OK) ; } DataBuffer[0] = 0x55 ; // Frame mode WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port,lnputBuffer,1) ; } for(i = 0: i < 5; i++) { DataBufferfO] = str[i] ; // Integer WriteComm(port,DataBuffer, 1 ); lnputBuffer[0] = 0x00 ; while ( lnputBuffer[0] != OxOA ) { ReadComm(port,lnputBuffer,1) ; } } DataBufferfO] * 0x40 ; // Enter WriteComm(port,DataBuffer, 1 ); lnputBuffer[0] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port,lnputBuffer,1) ; } lnputBuffer[0] = 0x00 ; while ( lnputBuffer[0] != 0x01 ) { ReadComm(port,lnputBuffer,1) ; } return((int)(lnputBuffer[0])); } int PASCAL SonyRecord(HWND hwnd, int port) { char str[6]; int i, input; const int N TRY = 5; BYTE DataBuffer[128] ; char lnputBuffer[ 128] ; int len ; char String[50] ; int ErrCode ; COMSTAT IpStat ; //sprintf(String,"Before Frame Mode") ; //MessageBox (hwnd, String, szAppName, MB.ICONEXCLAMATION | MB.OK) ; DataBuffer[0] - 0x55 ; // FRAME # MODE WriteComm(port,DataBuffer, 1); lnputBuffer[0] = 0x00 ; while ( lnputBuffer[0] != OxOA ) { ReadComm(port,lnputBuffer,1) ; //ErrCode = GetCommError(ρort,&lpStat) ; //sprintf(String,"Error Code = %d",ErrCode) ; //MessageBox (hwnd, String, szAppName, MBJCONEXCLAMATION MB.OK) ; } //sρrintf(String,"After Frame Mode") ; //MessageBox (hwnd, String, szAppName, MBJCONEXCLAMATION MB OK) ; DataBuffer[0] = OxEF ; // BLANK SEARCH DISABLE WriteComm(port,DataBuffer, 1 ); lnputBuffer[0] = 0x00 ; while ( lnρutBuffer[0] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } //sprintf(String,"After Blank enable Mode") ; //MessageBox (hwnd, String, szAppName, MB.ICONEXCLAMATION | MB.OK) ; sprintf(str,"%05ld",RecFrame); sprintf(String,"STR = ** %s ** ",str) ; DataBuffer[0] = OxEO ; // REC StndBy WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1 ) ; } while ( InputBufferfO] != 0x01 ) { ReadComm(port, InputBuffer, 1) ; } //sprintf(String,"After Rec StandBy") ; //MessageBox (hwnd. String, szAppName, MB.ICONEXCLAMATION | MB.OK) ; for(i = 0; i < 5; i++) { DataBufferfO] = str[i] ; // integer WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] OxOA ) { ReadComm(port, InputBuffer, 1) ; } } DataBufferfO] = 0x40 ; // Enter WriteComm(port,DataBuffer, 1 ); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } RecFrame++ ; sprintf(str,"%05ld",RecFrame); for(i = 0; i < 5; i++) { s3 DataBufferfO] = strfi] ; // Integer WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } } DataBufferfO] = 0x40 ; // Enter WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } DataBufferfO] = 0x40 ; // Enter WriteComm(ρort,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1 ) ; } InputBufferfO] = 0x00 ; while ( InputBufferfO] != 0x01 ) { ReadComm(ρort, InputBuffer, 1) ; } DataBufferfO] = 0xE6 ; // Frame Rec Mode WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } DataBufferfO] = 0xE9 ; // Record WriteComm(port,DataBuffer, 1); InputBufferfO] = 0x00 ; while ( InputBufferfO] != OxOA ) { ReadComm(port, InputBuffer, 1) ; } InputBufferfO] = 0x00 ; while ( InputBufferfO] != 0x01 ) { ReadComm(port, InputBuffer, 1) ; } return((int)(lnputBuffer[0])); } static char RgbFileName[50] ; UINT FAR PASCAL .export TimerProc(HWND hwnd, UINT message.UINT wParam, LONG IParam) { DWORD Sum ; int i ; switch ( TimeElapsed ) { case O: KillTimer(hwnd.l) ; if ( PictCount >= ToFr ) { InSerieMode = 0 ; break ; } sprintf(RgbFileName,"pict%d.rgb",PictCount++) ; load_picture_from_file(hwnd,RgbFileName) ; TimeElapsed++ ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; break ; case 1: KillTimer(hwnd,1) ; //SendMessage(hwnd, WM.COMMAND, IDM_AUTO_TRACK,0) ; if ( DummyFrames < DYMMIES ) { DummyFrames++ ; TimeElapsed++ ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; break ; } if ( ReplaceFlag == 1 ) { change.sign_by_tracking(hwnd,0) ; } TimeElapsed++ ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; break ; case 2: KilITimer(hwnd,1) ; drawjield Jc_screen(hwnd, SrcBmap, IsOddLine) ; //draw_to_screen(SrcBmap,0,SrcBmap->cols) ; TimeElapsed++ ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; break ; case 3: KillTimer(hwnd.l) ; if ( IsOddLine == 1 ) { // 1 I I I I I I SonyRecord(hwnd, PortNumber) ; //TTTTTTT //IsOddLine = 1 - IsOddLine ; / TimeElapsed = 0 ; //break ; } // I I I I I I I I IsOddLine = 1 - IsOddLine ; TιmeElapsed++ ; SetTimer(hwnd,1 ,1000, IpfnTimeProc) ; 5 break ; case 4: TimeElapsed++ ; break ; default: TimeElapsed = 0 ; break ; } return 1 } UINT FAR PASCAL .export TimerProc(HWND hwnd, UINT message.UINT wParam, LONG IParam) { DWORD Sum ; int i ; switch ( TimeElapsed ) { case O: K_irTimer(hwnd,1) ; //MessageBox (hwnd, "Before Search", szAppName, MBJCONEXCLAMATION | MB.OK) ; SonySearch(hwnd, SearchFrame, PortNumber) ; SearchFrame++ ; //MessageBox (hwnd, "After Search", szAppName, MBJCONEXCLAMATION | MB.OK) ; mfg_setvframe(RGB) ; mfg_dacmode(TRUE_24); TimeElapsed++ ; mfg_snap(CAMERA,PAGE1) ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; break ; ease l: KillTimer(hwnd,1) ; if ( PictCount >= ToFr ) { InSerieMode = 0 ; break ; } sprintf(RgbFileName,"pict%d.rgb",PictCount++) ; loadjieldjrom_card(hwnd,0) ; WriteRgb (hwnd.RgbFileName.SrcBmap) ; sprintf(RgbFileName,"pict%d.rgb",PictCount++) ; load_fιeld_from_card(hwnd,1) ; WriteRgb (hwnd.RgbFileName.SrcBmap) ; SetTimer(hwnd,1 ,40, IpfnTimeProc) ; TimeElapsed++ ; break ; default: TimeElapsed = 0 ; break ; } return 1 : } • / int PASCAL load.fιeldJrom_card(HWND hwnd, int NumOfField) { DWORD Size ; BYTE huge * RedBytes ; BYTE huge *GreenBytes ; BYTE huge *BlueBytes ; intj.k ; DWORD Ticks ; char StringfδO] ; Ticks = GetTickCount() ; //Size = (DWORD)572*(DWORD)768*(DWORD)3 ; Size = (DWORD)286 * (DWORD)768 * (DWORD)3 ; if ( SrcBmap != NULL ) bmJree(SrcBmap) ; SrcBmap = bm alloc(768,286,glModelColor); SrcBmap->gpic~= (BYTE. huge * )GlobalAllocPtr(GMEM.MOVEABLE,Size); RedBytes = SrcBmap->gpic ; GreenBytes = SrcBmap->gpic+1 ; BlueBytes = SrcBmap->gpic+2 ; mfg_setgframe(R); for ( k = NumOfField ; k < 572 ;k++ ) { mfg_brhline(PAGE0,0,k++,768,rpixarr) ; for (j = 0 ; j < 768 ; j++ ) { * RedBytes = φixarrfj] ; RedBytes += 3 ; } } mfg_setgframe(G); for ( k = NumOfField ; k < 572 ;k++ ) { mfg_brhiine(PAGE0,0,k++,768,rpixarr) ; for * (] = 0 ; j.< 768 ; j++ ) { • GreenBytes = rpixarrfj] ; GreenBytes += 3 ; } } mfg_setgframe(B); for ( k = NumOfField ; k < 572 ;k++ ) { Sill mfg_brhline(PAGE0,0,k++,768,φixarr) ; for ( j = 0 ; j < 768 ; j++ ) { *BlueBytes = φixarr ] ; BlueBytes += 3 ; } } sprintf(String,'Time = %ld",GetTickCount() - Ticks) ; MessageBox (hwnd, szAppName.String.MBJCONEXCLAMATION | MB.OK) ; teach rgbjoallete(hwnd) ; FileType = FILE.IS.RGB ; GetClientRect(hwnd,&ClientRect) ; create_norm_bmap(hwnd,SrcBmap,&Normap,ClientRect) ; return 1 ; } int PASCAL ioad_picture_from_card(HWND hwnd) { DWORD Size ; BYTE huge *RedBytes ; BYTE huge *GreenBytes ; BYTE huge *BlueBytes ; intj.k ; Size = (DWORD)572 * (DWORD)768 * (DWORD)3 ; if ( SrcBmap != NULL ) bm.free(SrcBmaρ) ; SrcBmap = bm.alloc(768,572,glModelColor); SrcBmap->gpic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size); RedBytes = SrcBmaρ->gρic ; GreenBytes = SrcBmap->gpic+1 ; BlueBytes = SrcBmap->gpic+2 ; mfg_setgframe(R); for ( k = 0 ; k < 572 ;k++ ) { mfg.brhline(PAGE0,0,k,768,rpixarr) ; for (1 = 0 ; j < 768 ; j++ ) { * RedBytes = φixarrD] ; RedBytes += 3 ; } } mfg_setgframe(G); ; } m% mfg_setgframe(B); for ( k = 0 ; k < 572 ;k++ ) { mfg_brhline(PAGE0,0,k,768,rpixarr) ; for ( j = 0 ; j < 768 ; j++ ) { • BlueBytes = φixarrfj] ; BlueBytes += 3 ; } } //if ( InterpMode == IN_TRILINEAR ) // build_pyramid(hwnd, SrcBmap) ; teach.rgb_pallete(hwnd) ; FileType = FILE.IS.RGB ; GetClientRect(hwnα\&ClientRect) ; create.norm_bmap(hwnd,SrcBmap,&Normap,ClientRect) ; return 1 ; int PASCAL load.picture from_fιle(HWND hwnd.char * FileName) { int ColorFactor ; int Width, Height ; DWORD SrcSize ; DWORD i ; if ( gIModelColor == GREY.MODEL ) { ColorFactor = 1 ; IpGreyRgb = ReadRGB (hwnd,FileName,&Width,&Height) ; IpPtr = IpGreyRgb ; } if ( gIModelColor == COLOR.MODEL ) { ColorFactor = 3 ; IpPtr = ReadRGB (hwnd,FileName,&Width,&Height) ; } IsRgb = 1 ; bmJree(SrcBmap) ; SrcBmap = bm_alloc(Width, Height, gIModelColor); if (SrcBmap == NULL) { MessageBox (hwnd, szAppName/'bm.alloc Failed!",MB_ICONEXCLAMATION | MB.OK) ; return 0 ; } SrcSize = (DWORD)Width * (DWORD)(Height) * (DWORD)(ColorFactor); SrcBmap->gpic = IpPtr ;. if ( SplitMode == 1 && SrcBmap != NULL) { split bitmap(SrcBmap,SrcBmaρ->typ,30) ; // NEW CALL } GetClientRect(hwnd,&ClientRect) ; 3&\ create_norm_bmap(hwnd,SrcBmap,&Normap,ClientRect) ; return 1 ; } int PASCAL drawjield Jo_screen(HWND hwnd.MYBITMAP * Bmap,int IsOdd) { int i,j ; BYTE huge *Ptr ; BYTE huge * PtrR ; BYTE huge *PtrG ; BYTE huge *PtrB ; int Cols, Rows ; lsOdd = 1- lsOdd ; // PATCH Cols = Bmap->cols ; Rows = (DWORD)(Bmap->rows)*(DWORD)2 ; Ptr = Bmap->gpic ; //Ptr += (DWORD)lsOdd*(DWORD)Cols*(DWORD)3 ; PtrR = Ptr ; PtrG = Ptr+1 ; PtrB s Ptr+2 ; mfg.setgframe(R); for ( i = IsOdd ; i < Rows ; i +=2 ) { for (j = 0 ; j < Cols ; j++ ) { φixarrfj] = * PtrR ; PtrR += 3 ; } //PtrR += (DWORD)Cols+(DWORD)3 ; mfg bwhline(PAGEO,0,i,Cols,φixarr) ; } mfg.setgframe(G); for ( i = IsOdd ; i < Rows ; i +=2 ) { for (j = 0 ; j < Cols ; j++ ) { φixarrfj] = * PtrG ; PtrG += 3 ; } //PtrG += (DWORD)Cols+(DWORD)3 ; mfg bwhline(PAGEO,0,i,Cols,φixarr) ; } mfg_setgframe(B); for ( i = IsOdd ; i < Rows ; i +=2 ) { for ( j = 0 ; j < Cols ; j++ ) { φixarrfj] = * PtrB ; PtrB += 3 ; } //PtrB += (DWORD)Cols+(DWORD)3 ; mfg_bwhline(PAGEO,0,i,Cols,φixarr) ; } R% return 1 ; } int PASCAL getJittness_of_vertexes(HWND hwnd.RECT Bound.MYBITMAP *Bmap, RPOINT * DstPnts,DWORD *Sum) { MYBITMAP *BoundedBmap=NULL ; MYBITMAP *DiffBmap =NULL ; RPOINT SrcPnts[4] ; l.cp_int_arr_to_RPOINT(SrcPnts, SignX, SigπY,4) ; create_grey_bounded_bitmap(Bound,Normap,&BoundedBmap) ;//Copy the area to // be changed into a //separate bitmap. perspective(hwnd,Bmap,Normap,SrcPnts, DstPnts, GREY.MODEL, &BasicTransf) ; // Perform perspective // grey of the current sign // with itself into NormBmap. substract_bitmaps(Bound,Normap,BoundedBmap,&DiffBmap) ; // Subtract BoundedBmap // from the transformed // sign area in NormBmap. sum_grey_bitmap_value(DiffBmap,Sum) ; bmJree(BoundedBmap) ; bm.free(DiffBmap) ; return 1 ; } int PASCAL replace sign(HWND hwnd.RPOINT * Dest) { MYBITMAP 'AlphaMap ; build_alpha_map(&AlphaMap, SrcBmap, Dest) ; perspective.al(hwnd,SubstBmap,SrcBmap,AlphaMap,SrcPoly, Dest, gIModelColor, &BasicTransf) ; bm.free(AlphaMap) ; create_norm.bmap(hwnd,SrcBmap,&Normap,GIBound) ; return 1 ; 3\\ int PASCAL smooth.values(double NewVal, double * OutVal, double "ValArr, int Num, double *Wheight) { int i ; double SumW = 0.0 ; double Calc ; for ( i = 0 ; i < Num-1 ; i++ ) { ValArr[i] = ValArr[i+1] ; } ValArr[Num-1] = NewVal ; Calc = 0 ; for ( i = 0 ; i < Num ; i++ ) { Calc += VaIArr[i] * Wheightfi] ; SumW += Wheightfi] ; } • OutVal = Calc/SumW ; return 1 ; } int PASCAL create_subs_sign(HWND hwnd) { //Perspective.Transform TpCurr ; Perspective.Transfor BasicTransf ; RECT Rectan ; int Cols, Rows ; DWORD Size ; RPOINT SrcPnts[4] ; RPOINT CrnPoly[4] ; //Quad2Quad(hwnd,SrcPoly,DstPoly,&TpCurr) ; l.fιnd_bound.rect(DstPoly, &Rectan) ; Cols = Rectan.right-Rectan.left+1 ; Rows = Rectan.bottom-Rectan.top+1 ; l.quadJn.new.origin(CrnPoly ! DstPoly,Rectan.left,Rectan.top,4) ; bm.free(Subs) ; Subs = bm.alloc(Cols,Rows,COLOR_MODEL) ; Size = (DWORD)Cols*(DWORD)Rows*(DWORD)3 ; Subs->gpic = (BYTE huge*)GlcbalAllocPtr(GMEM_MOVEABLE,Size) ; perspective(hwnd, SubstBmap, Subs.SrcPoly, CrnPoly, COLOR.MODEL, &BasicTransf) ; return 1 ; } int PASCAL fill.mask rect(MYBITMAP * Bmap) { int i,j,k,l ; int Cols, Rows ; int Count ; int Index = 0 ; Cols = Bmap->cols ; Rows = Bmap->rows ; Count = 0 ; for ( i= 0 ; i < Cols ; i++ ) { if ( BITMAP.PLACE(Bmap,0,i) == 0) Count++ ; else { if ( Count > 0 ) { OcclusionRectsflndexj.top = 0 ; OcclusionRectsflndexj.left = i - Count+1 ; OcclusionRects[lndex].bottom = Rows ; OcclusionRectsflndexj.right = i /*+Count/3 * / ; // IF BUG i. lndex++ ; Count = 0 ; } } } if ( Index == 0 && NumOfValidOccRects > 0 ) { OcclusionRectsfO] = VaiidOccRectsfO] ; OcclusionRectsfOj.right = min(OcclusionRectsfO].right+2,Cols-1) ; OcclusionRectsfOj.bottom = Rows ; for ( k = OcclusionRects[0].top ; k < OcclusionRectsfOj.bottom ; k++ ) { for ( I = OcclusionRectsfOj.left ; l< OcclusionRectsfOj.right ; !++ ) { BITMAP_PLACE(Bmap,k,l) = 0 ; } } Index = 1 ; } NumOfOccRects = Index ; return 1 ; } int PASCAL ValidateOccRects(MYBITMAP * Bmap) { int i, j,k,l ; RECT Intersection ; int Index = 0 ; 3Q2. for ( j = 0 ; j < NumOfValidOccRects ; j++ ) { for ( i = 0 ; i < NumOfOccRects ; i++ ) { lntersectRect(&Intersection,&(OcclusionRects[i]),&(ValidOccRectsD])) ; if ( Intersection, bottom == 0 ) { for ( k = OcclusionRectsfij.top ; k < OcclusionRectsfij.bottom ; k++ ) { for ( I = OcclusionRectsfij.left ; l< OcclusionRectsfi].right ; !++ ) { BITMAP PLACE(Bmap,k,l) = 1 ; } } } } } return 1 ; } int PASCAL copy.into_valid_rects() { int i ; for ( i = 0 ; i < NumOfOccRects ; i++ ) { ValidOccRectsfi] = OcclusionRectsfi] ; } NumOfValidOccRects = NumOfOccRects ; return 1 ; } int PASCAL enlarge_area_of_noise(MYBITMAP * From, MYBITMAP *Bmap) { int i, j ; int Cols.Rows ; RECT Rectan ; Cols = Bmap->cols ; Rows = Bmap->rows ; for ( j = 4 ; j < Cols-4 ; j+=3 ) { for ( i = 4 ; i < Rows -4 ; i++ ) { Rectan.top = i-3 ; Rectan.left = j-3 ; Rectan. right = j+3 ; Rectan.bottom = i+3 ; filter.noises by_rects(From,Rectan,8,25,Bmap) ; } } return 1 ; } a c ι~ #include <windows.h> #include <windowsx.h> #include <commdlg.h> #include <stdlib.h> #include <math.h> #include "const.h" #inciude "bitmap.h" #include "lines.h" #include "track.h" #include "min.mag.h" #include "lib.h" RECT Screen ; MYBITMAP FAR *dMaps[1 + DLVLS]; MYBITMAP FAR *iMaps[1 + ILVLS]; int PASCAL refine_alpha_edges(MYBITMAP* ) ; int PASCAL get.longest_occlusion(MYBITMAP * ,int ,int ) ; MYBITMAP FAR * bm_alloc(int xdim, int ydim, BMTYPE typ) { MYBITMAP FAR* bm; bm = (MYBITMAP FAR * ) GlobalAllocPtr(GMEM_MOVEABLE,sizeof(MYBITMAP)); if (bm — NULL ) return NULL ; bm->typ = typ; bm->cols = xdim; bm->rows = ydim; bm->gpic = NULL ; return (bm); } β double PASCAL bilinear(double xs, double ys, MYBITMAP FAR * bmap) { int yi = (int) ys; double dy = ys - (double) yi; int xi = (int) xs; double dx = xs - (double) xi; double gOO, g01 , g10, g11 , g1 , g2; if (xi < 01| xi >- bmap->cols) return (-1.0); if (yi < 01| yi >= bmap->rows) return (-1.0); gOO = B!TMAP.PLACE(bmap,yi,xi) ; g01 = (xi ss- bmap->cols - 1 ? gOO : BITMAP_PLACE(bmap.yi,xi+1)); g10 = (yi == bmap->rows - 1 ? gOO : BITMAP.PLACE(bmap,yi+1,xi)); g11 = (xi == bmap->cols - 1 || yi == bmap->rows - 1 ? gOO : BITMAP_PLACE(bmap.yi+1,xi+1)); g1 = gOO + (g01-gOO) * dx ; g2 = g10 + (g11-g10)*dx ; retum(g1 + (g2-g1) * dy) ; double PASCAL bilinear.red(double xs, double ys, MYBITMAP FAR* bmap) { int yi = (int) ys; double dy = ys - (double) yi; int xi = (int) xs; double dx = xs - (double) xi; double gOO, g01 , g10, g11 , g1 , g2; if (xi < 0 || xi >= bmap->cols) return (-1.0); if (yi < 0 || yi >= bmap->rows) return (-1.0); gOO = BITMAP_RGB_PLACE(bmap,yi,xi) ; g01 = (xi == bmap->cols - 1 ? gOO : *(BITMAP_RGB_PLACE_PTR(bmap,yi,xi+1))); g10 = (yi == bmap->rows - 1 ? gOO :*(BITMAP.RGB_PLACE_PTR(bmap,yi+1,xi))); g11 = (xi == bmap->cols - 1 || yi == bmap->rows - 1 ? gOO : * (BITMAP_RGB_PLACE_PTR(brτ.ap,yi+1,xi+1))); g1 =gOO*(1.0-dx) + g01 * dx; g2 = g10*(1.0-dx) + g11 * dx; return (g1 * (1.0 - dy) + g2 * dy); } double PASCAL bilinear.green(double xs, double ys, MYBITMAP FAR* bmap) if (xi < 01| xi >= bmap->cols) return (-1.0); if (yi < 01| yi >= bmap->rows) return (-1.0); gOO = * (BITMAP_RGB_PLACE.PTR(bmap,yi,xi)+1) ; g01 = (xi == bmap->cols - 1 ? gOO : * (BITMAP.RGB.PLACE_PTR(bmap,yi,xi+1 )+1 )); g10 = (yi == bmap->rows - 1 ? gOO : *(BITMAP_RGB.PLACE_PTR(bmap,yi+1 ,xi)+1 )); g11 = (xi == bmap->cols - 1 || yi == bmap->rows - 1 ? gOO : *(BITMAP_RGB_PLACE_PTR(bmap,yi+1,xi+1)+1)); g1 = g00*(1.O-dx) + gO1 * dx; g2 = g10*(1..0-dx) + g11 * dx; return (g1 * (1.0 - dy) + g2 * dy); } am double PASCAL bilinear_biue(double xs, double ys, MYBITMAP FAR* bmap) { int yi = (int) ys; double dy = ys - (double) yi; int xi = (int) xs; double dx = xs - (double) xi; double gOO, g01 , g10, g11 , g1 , g2; if (xi < 0 || xi >= bmap->cols) return (-1.0); if (yi < 0 || yi >= bmap->rows) return (-1.0); gOO = * (BITMAP_RGB_PLACE_PTR(bmap,yi,xi)+2) ; g01 = (xi == bmap->cols - 1 ? gOO :*(BITMAP_RGB.PLACE_PTR(bmap,yi,xi+1)+2)); g10 = (yi == bmap->rows - 1 ? gOO :*(BITMAP.RGB_PLACE.PTR(bmap,yi+1,xi)+2)); g11 = (xi == bmap->cols - 1 || yi == bmap->rows - 1 ? gOO : * (BITMAP_RGB.PLACE_PTR(bmap,yi+1,xi+1)+2)); g1 = gOO * (1.0 - x) + g01 * dx; g2 = g10 * (1.0 - dx) + g11 * dx; return (g1 * (1.0 - dy) + g2 * dy); } int PASCAL multmat(HWND hwnd.int Ma, int Na, int Nb, double *A, double *B, double * C) { int i, j, k; for (i = 0; i < Ma; i++) { for (j = 0; j < Nb; j++) { C[(DWORD)i * (DWORD)Nb + (DW0RD)j] = 0.0; for (k = 0; k < Na; k++) { C[(DW0RD)i * (DWORD)Nb + (DWORD)j] += Af(DWORD)i * (DWORD)Na + (DWORD)k] * Bf(DWORD)k * (DWORD)Nb + (DWORD)j]; } } } return 1 ; } double PASCAL resampleJrilinear(MYBITMAP FAR* bmap, double xs, double ys, ■double D.int ColorModel) { int id.i.mag ; double fMag.hMag ; double g1,g2,alpha,g ; if (D <= 1.0) // magnified pyramid level not used . return (bilinea cs, ys, bmap)); id = (int) ceil(D); for (i = 1; i <= DLVLS; i++) { mag = (1 « i); if (mag >= id) break; } if (i > DLVLS) // inteφlation is bi-linear return (bilinear(xs, ys, dMapsflLVLS])); fMag = mag; hMag = mag / 2; g1 = biiinear(xs / hMag, ys / hMag, dMapsfi - 1]); g2 = bilinear(xs / fMag, ys / fMag, dMapsfi]); alpha = (D - hMag) / hMag; g = g1 * (1.0 - alpha) + g2 * alpha; return (g); } double PASCAL resample Jrilinear_red(MYBITMAP FAR * bmap, double xs, double ys, 3rø double D.int ColorModel) { int id,i,mag ; double fMag.hMag ; double g1,g2,alρha,g ; if (D <= 1.0) // magnified pyramid level not used return (bilinear.red(xs, ys, bmap)); id = (int) ceil(D); for (i = 1; i <= DLVLS; i++) { mag = (1 « i); if (mag >= id) break; } if (i > DLVLS) // inteφlation is bi-linear return (bilinear_red(xs, ys, dMapsflLVLS])); fMag = mag; hMag = mag / 2; g1 = biiinear.red(xs / hMag, ys / hMag, dMapsfi - 1]); g2 = bilinear.red(xs /fMag, ys / fMag, dMapsfi]); alpha = (D - hMag) / hMag; g = g1 • (1.0 - alpha) + g2 * alpha; return (g); } double PASCAL resampleJriiinear_green(MYBITMAP FAR* bmap, double xs, double ys, double D.int ColorModel) { int id,i,mag ; double fMag.hMag ; double g1,g2,alpha,g ; if (D <= 1.0) // magnified pyramid level not used return (bilinear.green(xs, ys, bmap)); id = (int) ceil(D); for (i = 1; i <= DLVLS; i++) { mag = (1 « i); if (mag >= id) break; if (i > DLVLS) // inteφlation is bi-linear return (bilinear.green(xs, ys, dMapsflLVLS])); fMag = mag; hMag = mag / 2; g1 = bilinear.green(xs / hMag, ys / hMag, dMapsfi - 1]); g2 = biiinear_green(xs / fMag, ys / fMag, dMapsfi]); alpha = (D - hMag) / hMag; g = g1 * (1.0 - alpha) + g2 * alpha; return (g); } double PASCAL resample_trilinear.blue(MYBITMAP FAR* bmap, double xs, double ys, double D.int ColorModel) { int id,i,mag ; double fMag.hMag ; double g1,g2,alpha,g ; if (D <= 1.0) // magnified pyramid level not used return (bilinear.blue(xs, ys, bmap)); id = (int) ceil(D); for (i = 1; i <= DLVLS; i++) { mag = (1 « i); if (mag >= id) break; } 3θ| if (i > DLVLS) // inteφlation is bi-linear return (bilinear_blue(xs, ys, dMapsflLVLS])); fMag = mag; hMag = mag / 2; g1 = biiinear_blue(xs / hMag, ys / hMag, dMapsfi - 1]); g2 = bilinear.blue(xs / fMag, ys / fMag, dMapsfi]); alpha = (D - hMag) / hMag; g = g1 * (1.0 - alpha) + g2 * alpha; return (g); int PASCAL build_pyramid(HWND hwnd, MYBITMAP FAR * SrcBmap) { int i ; dMapsfO] = iMapsfO] = SrcBmap; for (i = 1; i <- DLVLS; i++) { dMapsfi] = minify(hwnd, dMapsfi - 1], 2); } return 1 ; } int PASCAL bm_free(MYBITMAP FAR * BtMap) { if ( BtMap != NULL ) { GlobalFreePtr(BtMap->gpic) ; GlobalFreePtr(BtMap) ; } return 1 ; } int PASCAL find .orizJine(MYBITMAP * Bmap,POINT Pointi , POINT Point2, RPOINT *ϋne) { int ij.Ri.Rj ; double Luma1f7][7] ; double Luma2[7][7] ; double r.g.b ; double Tresh = 70 ; RPOINT Found1,Found2 ; int Found ; for ( i = Pointi .y-3, Ri = 0 ; Ri < 7 ; i++,Ri++) { for ( j = Pointi .x-3, Rj = 0 ; Rj < 7 ; j++,Rj++ ) { r = * (BITMAP_RGB_PLACE_PTR(Bmap,i.j)) ; g = *(BITMAP.RGB.PLACE_PTR(Bmap,i,j)+1) b = *(BITMAP_RGB_PLACE_PTR(Bmap,i,j)+2) Lumal fRi][Rj] = r * 0.299 + g * 0.587 + b * 0.114; } } for ( i = Point2.y-3, Ri = 0 ; Ri < 7 ; i++,Ri++) { for ( j = Point2.x-3, Rj = 0 ; Rj < 7 ; j++,Rj++ ) { r = *(BITMAP_RGB_PLACE_PTR(Bmap,i,j)) ; g = • (BITMAP.RGB_PLACE.PTR(Bmap,i,j)+1J ; b = *(BITMAP.RGB_PLACE_PTR(Bmap,i,j)+2) ; Luma2[Ri][Rj] = r * 0.299 + g * 0.587 + b * 0.114; } } Found = 0 ; Found1.x = Pointi .x ; Foundl .y = Pointi .y ; or ( i = 1 ; i < 6 && Found == 0; i++ ) { for ( j = 0 ; j < 6 ; j++ ) { if ( fabs(Luma1[i-1]03-Luma1fi]D]) >= Tresh ) { if ( fabs(Luma1fi-1][j+1] - Lumal [i][j+1 ]) >= Tresh || fabs(Luma1[i+1]0+1] - Lumal [i][j+1]) >= Tresh ) { Foundl .x = Pointi .x -3+j ; . Foundl. y = Point y -3+i ; Found = 1 ; break ; } } } } Found = 0 ; Found2.x = Point2.x ; Found2.y = Point2.y ; for ( i = 1 ; i < 6 && Found == 0 ; i++ ) { for ( j = 0 ; j < 6 ; j++ ) { if ( fabs(Luma2fi-1]0]-Luma2[i]D]) >= Tresh ) { if ( fabs(Luma2[i-1]fj+1] - Luma2[i]D+1]) >= Tresh || fabs(Luma2[i+1]D+1] - Luma2[i]0+1]) >= Tresh ) { Found2.x = Point2.x -3+j ; Found2.y = PointZy -3+i ; Found = 1 ; break ; } } } } Line->y = (Found2.x * Found1.y-Found2.y*Found1.x)/(Found2.x-Found1.x) ; Line->x = (Foundl .y-Line->y)/Found1.x ; return 1 ; } int PASCAL fιnd.vertic.line(MYBITMAP *Bmap,POINT Pointi, POINT Point2, RPOINT * Line) { int ij.Ri.Rj ; double Luma1[7][7] ; double Luma2[7]f7] ; double r,g,b ; double Tresh = 70 ; RPOINT Foundl , Found2 ; int Foun ; for ( i = Pointi .y-3, Ri = 0 ; Ri < 7 ; i++,Ri++) { for ( j = Pointi .x-3, Rj = 0 ; Rj < 7 ; j++,Rj++ ) { 3θ r = *(BITMAP_RGB_PLACE.PTR(Bmap,i,j)) ; g = *(BITMAP_RGB_PLACE.PTR(Bmap,i,j)+1) ; b = *(BITMAP_RGB_PLACE.PTR(Bmap,i,j)+2) ; Lumal [RijfRj] = r * 0.299 + g * 0.587 + b * 0.114; } } for ( i = Point2.y-3, Ri = 0 ; Ri < 7 ; i++,Ri++) { for ( j = Point2.x-3, Rj = 0 ; Rj < 7 ; j++,Rj++ ) { r = *(BITMAP_RGB_PLACE_PTR(Bmap,i,j)) ; g = *(BITMAP_RGB_PLACE.PTR(Bmap,i,j)+1) b = * (BITMAP_RGB_PLACE_PTR(Bmap,i,j)+2) Luma2[Ri][Rj] = r * 0.299 + g * 0.587 + b * 0.114; } } Found = 0 ; Foundl .x = Pointi .x ; Foundl .y = Pointi .y ; for ( i = 0 ; i < 6 && Found == 0; i++ ) { for (j = 0 ; j < 6 ; j++ ) { if ( fabs(Luma1fi]Q]-Luma1 [i][j+1]) >= Tresh ) { if ( fabs(Luma1[i+1][j] - Lumal [i+1]ϋ+1]) >= fresh ) { Foundl .x = Pointi .x -3+j ; Foundl .y = Pointi .y -3+i ; Found = 1 ; break ; } } } } Found = 0 ; Found2.x = Point2.x ; Found2.y = Point2.y ; or ( i = 0 ; i < 6 && Found == 0 ; i++ ) { f or ( j = 0 ; j < 6 ; j++ ) { if ( fabs(Luma2fi]0]-Luma2[i]0+1j) >= Tresh ) { if ( fabs(Luma2[i+1][j] - Luma2[i+1]D+1]) >= Tresh ) { Found2.x = Point2.x -3+j ; Found2.y = Point2.y -3+i ; Found = 1 ; break ; } } } } if ( Found2.x == Foundl .x ) { Line->y = 0.0 ; Line->x = Found 1.x ; } else { Line->y = (Found2.x*Found1.y-Found2.y*Found1.x)/(Found2.x-Found1.x) ; Line->x = (Foundl .y-Line->y)/Found1.x ; } return 1 ; } #defιne HSx 5 /* Half search area (x) 7 #define HSy 5/ * Half search area (y) 7 #define HWx 4 /* Half correlation window (x) 7 #defιne HWy 4 /* Half correlation window (y) 7 int PASCAL create_lum_bmap(MYBITMAP *Bmap, MYBITMAP **LumBmap) { BYTE huge * Tmp; BYTE huge * TmpB ; int Cols, Rows ; DWORD Size ; DWORD i ; Cols = Bmap->cols ; Rows = Bmap->rows ; Tmp = Bmap->gpic ; 3θfc> bm_free(*LumBmap) ; • LumBmap = bm.alloc(Cols,Rows,GREY_MODEL); Size = (DWORD)Cols * (DWORD)Rows ; ( * LumBmap)->gpic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) TmpB = (*LumBmap)->gpic ; Tmp = Bmap->gpic ; for ( i = 0 ; i < Size ; i++ ) { *(TmpB++) = (BYTE)((double)(*(Tmp++)) * 0.299 + (double)*(Tmp++) * 0.587 + (double)*(Tmp++) * 0.114); } return 1 ; } int PASCAL duplicate_bmap(MYBITMAP * FrBmap, MYBITMAP ToBmap.int Type) { BYTE huge * Tmp; BYTE huge * TmpB ; int Cols, Rows ; DWORD Size ; DWORD i ; int ColorFactor=1 ; Cols = FrBmap->cols ; Rows = FrBmap->rows ; if ( Type == COLOR.MODEL ) ColorFactor = 3 ; Tmp = FrBmap->gpic ; if ( ToBmap != NULL ) bmJree(ToBmap) ; *ToBmap = bm_alloc(Cols,Rows,Type); Size.= (DWORD)Cois*(DWORD)Rows * (DWORD)ColorFactor ; 3c1 (*ToBmap)->gρic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; TmpB = ( * ToBmap)->gpic ; Tmp = FrBmap->gpic ; for ( i = 0 ; i < Size ;i++ ) { *(TmpB++) = *(Tmp++) ; } return 1 ; } int PASCAL create_grey_bounded_bitmaρ(RECT area, MYBITMAP • Bmap, MYBITMAP * *BoundBmap) { int i, j ; int Cols, Rows ; DWORD Size ; BYTE huge* Tmp ; Cols = area, right - area, left ; Rows = area. bottom - area, top ; bm_free( * BoundBmap) ; *BoundBmap = bm_alloc(Cols,Rows,GREY_MODEL) ; Size = (DWORD)CoIs*(DWORD)Rows ; (*BoundBmap)->gρic = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; Tmp = ( * BoundBmap)->gpic ; for ( i = area.top ; i < area.bottom ; i++ ) { for ( j = area, left ; j < area.right ; j++ ) { *(Tmp++) = BITMAP.PLACE(Bmap,i.j) ; } } return 1 ; } 3θS int PASCAL substract_bitmaps(RECT area.MYBITMAP "From.MYBITMAP *Subs, MYBITMAP ** Diff) { DWORD Size ; int Cols, Rows ; int i, j ; BYTE huge * Tmp ; Cols = Subs->cols ; Rows = Subs->rows ; bm_free( * Diff) ; *Diff = bm.alloc(Cols,Rows,GREY.MODEL) ; Size = (DWORD)Cols*(DWORD)Rows ; (*Diff)->gpic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; Tmp = (*Diff)->gpic ; for ( i = area.top ; i < area.bottom ; i++ ) { for ( j = area, left ; j < area. right ; j++ ) { *(Tmp++) = (BYTE)abs((int)(BITMAP_PLACE(From,i,j)- BITMAP.PLACE(Subs,i-area.top,j-area.left))) ; } } return 1 ; } int PASCAL insert_grey_bounded_bitmap(RECT area.MYBITMAP *Tolnsert, MYBITMAP *lnto) { int i, j ; for ( i = area.top ; i< area.bottom ; i++ ) { for ( j = area. left ; j< area.right ; j++ ) { BITMAP_PLACE(lnto,i,j) = BITMAP_PLACE(Tolnsert,i-area.top,j-area.left) ; } } 3cfi return 1 ; } int PASCAL copy_grey_rectJrom.frame(MYBITMAP * lnto, MYBITMAP • From, € RECT area) { int i.j ; for ( i = area.top ; i < area.bottom ; i++ ) { for ( j = area.left ; j < area.right ; j++ ) { BITMAP_PLACE(lnto,i-area.top,j-area.left) = BITMAP_PLACE(From,i,j) » } } return 1 ; } int PASCAL build_alpha_map(MYBITMAP * * AlphaMap, MYBITMAP • SrcBmap.RPOINT *Vertex) { int i,j ; RECT Rectan ; int Cols, Rows ; SEG lines[4] ; DWORD Size ; RPOINT Points[4] ; double Xval,Xmin,Xmax ; int Curr ; Cols = SrcBmap->cols ; Rows = SrcBmap->rows ; l.find.bound_rect(Vertex, &Rectan) ; for ( i = 0 ; i < 3 ; i++ ) { mksegment(Vertex[i].x, Vertexfij.y, Vertex[i+1].x, Vertex[i+1].y,&(lines[i])) ; } 3.C mksegment(Vertex[3].x, Vertex[3].y, Vertex[0].x, Vertex[0].y,&(lines[3])) • AlphaMap = bm_alloc(Cols,Rows,GREY_MODEL); Size = (DWORD)Cols * (DWORD)Rows ; (*AlphaMap)->gpic = (BYTE huge * )GlobalAllocPtr(GMEM.MOVEABLE | GMEM_ZEROINIT,Size) ; for( i = Rectan.top ; i < Rectan. bottom ; i++ ) { Curr = 0 ; for (j = 0 ; j < 4 ; j++ ) { if ( linesfjj.a != 0.0 ) { Xval = -1.0 *(lines[j].b*(double)i + lines[j].c)/linesfj].a ; if ( Xval <= Cols && Xval >= 0 ) { if ( i <= (int)(lines[j].ymax) && i >= (int)(lines[j].ymin) ) PointsfCurr++].x = Xval ; } } } Xmin = PointsfOj.x ; Xmax = Xmin ; for ( j = 1 ; j < Curr ; j++ ) { Xmin = min(Points[j].x,Xmin) ; Xmax = max(Pointsfj].x,Xmax) ; } for ( j = (int)Xmin ; j <= (int)Xmax ; j++ ) { BITMAP.PLACE((*AlphaMap),i,j) = 1 ; } } refιne_alpha.edges( * AlphaMap) ; return 1 ; } int PASCAL split_bitmap(MYB.TMAP * Bmap,int ColorModel.int FromRow) { DWORD i.k ; int Cols, Rows ; DWORD Place ; BYTE huge *Dup ; int ColorFactor ; 3l l DWORD Offset, Size, Offset2 ; ColorFactor = 3 ; Cols = Bmap->cols ; Rows = Bmap->rows ; Size = (DWORD)Rows * (DWORD)Cols * (DWORD)ColorFactor ; Rows = (Bmap->rows-FromRow) 12 ; if ( ColorModel == GREY.MODEL ) ColorFactor = 1; Offset = (DWORD)FromRow * (DWORD)Cols * (DWORD)ColorFactor ; Place = (DWORD)Rows*(DWORD)Cols * (DWORD)ColorFactor ; Dup = Bmap->gpic + Size - Offset*(DWORD)2 ; Offset2 = Offset * (DWORD)2 ; for ( i = 0 ; i < Offset2 ; i++ ) { *(Dup++) = *(Bmap->gpic +Place+i) ; } Dup = Bmap->gpic+Place ; k = 0 ; for ( i = Offset ; i < Place ; i++ ) { *(Dup+ k++) = *(Bmap->gpic +i) ; } Size = (DWORD)Cols * (DWORD)6 * (DWORD)ColorFactor ; // 6 Rows of Black, for ( i = 0 ; i < Size ; i++ ) { *(Duρ++) = 0 ; } return 1 ; } int PASCAL refιne_alpha_edges(MYBITMAP* AlphaMap) { int i,j; int Cols, Rows ; BYTE Far.Close ; int Count = 0 ; Cols = AlphaMap->cols ; Rows = AlphaMap->rows ; Far = 170 ; Close - 85 ; for ( i = 2 ; i < Rows ; i++ ) { for ( j = 2 ; j < Cols-1 ; j++ ) { if ( BITMAP_PLACE(AlphaMap,i,j) == 1 ) { r if ( BITMAP_PLACE(AlphaMap,i.j-1) == 0 ) { BITMAP_PLACE(AlphaMap,i,j-2) = Far ; BITMAP_PLACE(AlphaMap,i,j-1) = Close ; } " rf ( BITMAP_PLACE(AlphaMap,i,j+1 ) == 0 ) { BITMAP.PLACE(AlphaMap,i,j+2) = Far ; BITMAP_PLACE(AlphaMap,i.j+1 ) = Close ; j ++ ; } 7 if ( BITMAP_PLACE(AlphaMap,i-1 j) == 0 ) { BITMAP_PLACE(AlphaMap,i,j) = Far ; BITMAP.PLACE(AlphaMap,i+1 ,j) = Close ; } " rf ( BITMAP_PLACE(AlphaMap,i+1,j) == 0 ) { BITMAP_PLACE(AlphaMap,ij) = Far ; BITMAP_PLACE(AlphaMap,i-1.j) = Close ; } } } } r for ( i = 2 ; i < Rows ; i++) { for ( j = 2 ; j < Cols ; j++ ) { if ( BITMAP_PLACE(AlphaMap,i,j) > 2 && BITMAP_PLACE(AlphaMap,i.j-1 ) ==0 ) { ArrayfCountj.x = j-1 ; Array[Count++].y = i ; } } } i 3 for ( i = 0 ; i < Count-1 ; i++ ) { Len = Array[i].x-Array[i+1].x ; if ( Len == 0 ) continue ; Unit = 256/Len ; Line = Array[i].y ; for ( j = Array[i].x, k = 1 ; Len > 0 ; Len- ) { BITMAP_PLACE(AlphaMap,Line,j) = (DWORD)Unit * (DWORD)k ; j- ; k++ ; } } 7 return 1 ; } int PASCAL get_mask_bitmap(HWND hwnd.MYBITMAP * Bmap,int Tresh.MYBITMAP -MaskBmap) { int Cols, Rows ; BYTE huge Tmp ; BYTE huge *BmapPtr ; DWORD Size ,indx ; int i,j,k ; int Limit.Count, Value ; MYBITMAP ToBmap ; Cols = Bmap->cols ; Rows = Bmap->rows ; bm_free( * MaskBmap) ; • MaskBmap = bm.alloc(Cols,Rows,GREY_MODEL) ; Size = (DWORD)Cols*(DWORD)Rows ; ( * MaskBmap)->gpic = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; Tmp = (*MaskBmap)->gpic ; BmapPtr = Bmap->gpic ; for ( indx = 0 ; indx < Size ; indx++ ) { T T SHEET RULE 26^ if ( *(BmaρPtr++) <= Tresh ) { * (Tmp++) = 1 ; } else { * (Tmp++) = 0 ; } } duplicate_bmap(*MaskBmap, &ToBmap, GREY.MODEL) ; enlarge_area.of.noise(ToBmap, * MaskBmap) ; WriteGreyRgb (hwnd,"mask0.rgb", * MaskBmap) ; brn_free(ToBmap) ; Limit = Rows/3 ; for ( j = 0 ; j < Cols ; j++ ) { 1/ 0 Means Occlusion. 1 Means OK. Count = get Jongest_occlusion( * MaskBmap,j, Rows) ; if ( Count < Limit ) { Value = 1 ; // //for ( i = 0 ; i < Rows ; i++ ) { // BITMAP_PLACE(( * MaskBmap),i,j) = 1 ; II) } else Value = 0 ; // for ( i = 0 ; i < Rows ; i++ ) { // BITMAP_PLACE(( * MaskBmap),i,j) = Value ; // } // } Count = 0 ; or ( j = 0 ; j < Cols ; j++ ) { if ( BITMAP.PLACE((*MaskBmap),0.j) == 0 ) Count++ ; else { if ( Count == 0 ) continue ; if ( Count < 6 ) { for ( k = j-Count ; Count > 0 ; Count-, k++ ) { for ( i = 0 ; i < Rows ; i++ ) { BITMAP_PLACE(( * MaskBmap),i,k) = 1 ; } } } else { // Count >= 6 3(5 ( i = 0 ; i < Rows ; i++ ) { if ( j > (Count+12) ) Limit = j-(Count+12) ; else Limit = 0 ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; if ( j > (Count+11 ) ) Limit = j-(Count+11 ) ; else Limit = 0 ; BITMAP_PLACE(( * MaskBmap),i, Limit) = 0 ; if ( j > (Count+10) ) Limit = j-(Count+10) ; else Limit = 0 ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; if ( j > (Count+9) ) Limit = j-(Count+9) ; else Limit = 0 ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; if ( j > (Count+8) ) Limit = j-(Count+8) ; else Limit = 0 ; BITMAP_PLACE(( * MaskBmap),i, Limit) = 0 ; if ( j > (Count+7) ) Limit =j-(Count+7) ; else Limit = 0 ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; if ( j > (Count+6) ) Limit = j-(Count+6) ; else Limit = 0 ; BlTMAP_PLACE(( * MaskBmap),i,Limit) = 0 ; if ( j > (Count+5) ) Limit = j-(Count+5) ; else Limit = 0 ; BITMAP_PLACE(( * MaskBmap),i,Limit) = 0 ; if ( j > (Count+4) ) Limit =j-(Count+4) ; else Limit = 0 ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; if ( j > (Count+3) ) Limit = j-(Count+3) ; else Limit = 0 ; BITMAP_PLACE(( * MaskBmaρ),i,Limit) = 0 ; if ( j > (Count+2) ) Limit = j-(Count+2) ; else Limit = 0 ; BITMAP_Pl_ACE((*MaskBmap),i, Limit) = 0 ; if ( j > (Count+1 ) ) Limit = j-(Count+1 ) ; else Limit = 0 ; BITMAP_PLACE(( * MaskBmap),i,Limit) = 0 ; B_TMAP.PLACE((*MaskBmap),ij-Count) = 0; BITMAP_PLACE((*MaskBmaρ),i,j) = 0 ; Limit = min(j+1,Cols-1) ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; Limit = min(j+2,Cols-1) ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; Limit = min(j+3,Cols-1) ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0; Limit = min(j+4,Cols-1 ) ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; Limit = min(j+5,Cols-1) ; B_TMAP_PLACE((*MaskBmap),i,ϋmit) = 0 ; Limit = min(j+6,Cois-1) ; BITMAP_PLACE((*MaskBmap),i,Limit) = 0 ; Limit = min(j + 7,Cols-1) ; BITMAP.PLACE(( * MaskBmap),i,Limit) = 0 ; Limit = minϋ+8,Cols-1) ; BITMAP_PLACE(( * MaskBmap),i, Limit) = 0 ; } j = min(j+6,Cols-1) ; Count = 0 ; } } } return 1 ; } 7 int PASCAL get_mask_bitmap(HWND hwnd.MYBITMAP * Bmap,int Tresh.MYBITMAP -MaskBmap) { iπt Cols, Rows ; BYTE huge Tmp ; BYTE huge *BmapPtr ; DWORD Size .indx ; int i.j,k ; int Limit, Count, Value ; MYBITMAP TempBmap ; 3π £ • RECT Rectan ; Cols = Bmap->cols ; Rows = Bmap->rows ; TempBmap = bm_alloc(Cols,Rows,GREY.MODEL) ; Size = (DWORD)Cols*(DWORD)Rows ; TempBmap->gpic = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) Tmp = TempBmap->gpic ; BmapPtr = Bmap->gpic ; for ( indx = 0 ; indx < Size ; indx++ ) { if ( *(BmapPtr++) <= Tresh ) { * (Tmp++) = 1 ; } else { * (Tmp++) = 0 ; } } Limit = Rows/3 ; for ( j = 0 ; j < Cols ; j++ ) { I/ O Means Occlusion. .1 Means OK. Count = get_longest_occlusion(TempBmap,j,Rows) ; if ( Count >= Limit ) { BlTMAP.PLACE(TempBmap,0,j) = 0 ; } else { BiTMAP_PLACE(TempBmap,0 j) = 1 ; } Count = 0 ; or ( j = 0 ; j < Cols ; j++ ) { if ( BrTMAP_PLACE(TempBmap.O,j) == 0 ) Count++ ; else { if ( Count == 0 ) continue ; if ( Count < 6 ) { for ( k = j-Count ; Count > 0 ; Count-, k++ ) { for ( i = 0 ; i < Rows ; i++ ) { BITMAP_PLACE(TempBmap,i,k) = 1 ; } 3iS } } else { // Count >= 6 for ( k = j-Count ; Count > 0 ; Count-, k++ ) { for ( i = 0 ; i < Rows ; i++ ) { BITMAP_PLACE(TempBmap,i,k) = 0 ; } } for ( i = 0 ; i < Rows ; i++ ) { if ( j > (Count+5) ) Limit = j-(Count+5) ; else Limit = 0 ; B.TMAP_PLACE(TempBmap,i,Limit) = 0 ; if ( j > (Count+4) ) Limit = j-(Count+4) ; else Limit = 0 ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; if ( j > (Count+3) ) Limit = j-(Count+3) ; else Limit = 0 ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; if ( j > (Count+2) ) Limit = j-(Count+2) ; else Limit = 0 ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; rf ( j > (Count+1 ) ) Limit = j-(Count+1 ) ; else Limit = 0 ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; Limit = min(j+1,Cols-1) ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; Limit = min(j+2,Cols-1) ; BITMAP_PLACE(TempBmap,i,Limit) = 0 ; Limit = min(j+3,Cols-1) ; BITMAP_PLACE(TempBmap,i,Limit) = 0 Limit = min(j+4.Cols-1) ; BITMAP_PLACE(TemρBmap,i, Limit) = 0; Limit = min(j+5,Cols-1 ) ; B.TMAP_PI-ACE(TempBmap,i,Limit) = 0 j = minG+5,Cols-1 ) ; } } Count = 0 ; 3I C / } duplicate_bmap(TempBmap, MaskBmap, GREY.MODEL) ; //WriteGreyRgb (hwnd,"mask0.rgb",*MaskBmap) ; for ( i = 5 ; i < Rows-5 ; i++ ) { for ( j = 5; j < Cols-5 ; j++ ) { if ( BITMAP.PLACE(TempBmap,i,j) == 0 ) { Rectan.top = i-5 ; Rectan. left = j ; Rectan. bottom = i+5 ; Rectan.right = j+5 ; filter.noises.by.rects(TempBmap, Rectan,6,30, * MaskBmap) ; Rectan. left = j-5 ; Rectan. right = j ; filter.noises_by.rects(TempBmap, Rectan,6,30. * MaskBmap) ; Rectan.right = j+5 ; filter.noises.by.rects(TempBmap, Rectan, 11,55, * MaskBmap) ; } } } bmJree(TempBmap) ; //WriteGreyRgb (hwnd,"mask1.rgb", * MaskBmap) ; //Limit = Rows/4 ; for ( j = 1 ; j < Cols-2 ; j++ ) { 11 Means Occlusion. 1 Means OK //Count = get Jongest_occlusion( * MaskBmap,j, Rows) : if ( B_TMAP.PLACE(( * MaskBmap),0,j-1) == 1 && (BITMAP_PLACE(( * MaskBmap),0,j+2)== 1 || BITMAP_PLACE((*MaskBmap),0,j+1 ) = 1 ) ; { for ( i = 0 ; i < Rows ; i++ ) { BITMAP_PLACE((*MaskBmap),i,j) = 1 ; } } } //WriteGreyRgb ^hwnd,"mask2.rgb", * MaskBmaρ) ; return 1 : } int PASCAL getJongest_occiusion(MYB!TMAP * Bmap,in; col.int rows) { int i ; int Count = 0 ; int Longest = 0 ; for ( i = 0 ; i < rows ; i++ ) { if ( BITMAP_PLACE(Bmap,i,col) == 0 ) Count++ ; else { if ( Count > Longest ) { Longest = Count ; Count = 0 ; } } } if ( Count > Longest ) { Longest = Count ; } return Longest ; } double PASCAL bilinear.rgb(doubie xs, double ys, MYBITMAP FAR* bmap, double * Ptr) PtrXY = BITMAP_RGB.PLACE_PTR(bmap,yi,xi) ; PtrX1 = BITMAP.RGB_PLACE_PTR(bmap,yi,xi+1) ; PtrYl = BITMAP_RGB_PLACE_PTR(bmap,yi+1 ,xi) ; PtrX1Y1 = BITMAP_RGB_PLACE_PTR(bmap,yi+1,xi+1) ; 3»| SUBSTITUTE SHEET (RULE 26^ 95/10919 gOO = PtrXYfO] ; g01 = (xi == bmap->cols - ? gOO : PtrXI fO]); g10 = (yi == bmap->rows - 1 ? gOO : PtrYl fO]); g11 = (xi == bmap->cols - 1 || yi ~ bmap->rows - 1 ? gOO : PtrXI Y1[0]); g1 = gOO*(1.0-dx) + g01 *dx; g2 = g10*(1.0-dx) + g11 * dx; Ptr[0] = g1 * (1.0-dy) + g2 * dy; gOO = PtrXY[1] ; g01 = (xi == bmap->cols - 1 ? gOO : PtrXI [1]); g10 s (yi == bmap->rows - 1 ? gOO : PtrYl f1]); g11 = (xi == bmap->cols - 1 JJ yi == bmap->rows - 1 ? gOO : PtrXI Y1[1]); g1 =gOO * (1.0-dx) + g01 *dx; g2 = g10*(1.0-dx) + g11 *dx; Ptr[1] = g1 * (1.0-dy) + g2*dy; gOO = PtrXY[2] ; g01 = (xi == bmap->cols - 1 ? gOO : PtrXI f2]); g10 = (yi == bmap->rows - 1 ? gOO : PtrYl [2]); g11 = (xi == bmap->cols - 1 || yi == bmap->rows - 1 ? gOO : PtrXI Y1 [2]); g1 =g00 * (1.O-dx) + gO1 * dx; g2 = g10 β (1.0-dx) + g11 *dx; Ptrf2] = g1 * (1.0-dy) + g2*dy; return (0.0); } iπt PASCAL spIit_bitmapJrame(MYBITMAP • SrcBmap.MYBITMAP ~F1, MYBITMAP -F2) { int Rows, Cols, MidRows ; DWORD Size, Limit, indx ; int i, ColorFactor ; BYTE huge * CurrPtr; BYTE huge * Ptr; Rows = SrcBmap->rows ; Cols = SrcBmap->cols ; • 32Λ LE 26 if ( SrcBmap->typ == COLOR.MODEL ) ColorFactor = 3 ; else ColorFactor = 1 ; if ( Rows %2 == 0 ) { MidRows = Rows/2 ; } else { MidRows s Rows/2 +1 ; } Size = (DWORD)MidRows*(DWORD)Co!s*(DWORD)ColorFactor ; *F1 = bm_alloc(Cols,MidRows,SrcBmap->typ) ; (*F1)->gpic = (BYTE huge*)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; Limit = (DWORD)Cols * (DWORD)ColorFactor ; CurτPtr = (*F1)->gpic ; for ( i = 0 ; i < Rows ; i+=2 ) { if ( ColorFactor == 1 ) { Ptr = BITMAP.PLACE_PTR(SrcBmap,i,0) ; } else { Ptr = BITMAP_RGB_PLACE.PTR(SrcBmap,i,0) ; } for ( indx = 0 ; indx < Limit ; indx++ ) { * (CurrPtr++) = *(Ptr++) ; } } MidRows = Rows - MidRows ; Size = (DWORD)MidRows * (DWORD)Cols * (DWORD)ColorFactor ; * F2 = bm.alloc(Cols, MidRows, SrcBmap->typ) ; ( * F2)->gpic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; CurrPtr = ( * F2)->gpic ; for ( i = 1 ; i < Rows ; i+=2 ) { if ( ColorFactor == 1 ) { Ptr = BITMAP.PLACE_PTR(SrcBmap,i,0) ; } else { Ptr = BITMAP_RGB.PLACE.PTR(SrcBmap,i,0) ; } for ( indx = 0 ; indx < Limit ; indx++ ) { * (CurrPtr++) = * (Ptr++) ; } } 3Λ3 return 1 ; } int PASCAL sum_greyJ_itmap.value(MYB!TMAP * Bmap,DWORD * Sum) { DWORD i; int Cols.Rows ; DWORD Size ; DWORD CurrSum ; BYTE huge *Ptr ; Cols = Bmap->cols ; Rows = Bmap->rows ; Ptr = Bmap->gpic ; Size = (DWORD)Cols*(DWORD)Rows ; CurrSum = 0 ; for ( i = 0 ; i < Size ; i++ ) { CurrSum += * (Ptr++) ; } * Sum = CurrSum ; return 1 ; } int PASCAL filter_noises_by_rects(MYBITMAP *Source,RECT Rectan.int LowLimit, int HighLimit,MYBITMAP Target) { int i,j ; int Count = 0 ; int Left, Right.Top, Bottom ; int Value ; Left = Rectan. left ; Top = Rectan.top ; Right = Rectan. right ; 3c3α Bottom = Rectan.bottom ; for ( i = Top ; i < Bottom ; i++ ) { for (j = Left ; j < Right ; j++ ) { rf ( BITMAP_PLACE(Source,i,j) == 0 ) Count++ ; } } Value = -1 ; If ( Count < LowLimit ) Value = 1 ; if ( Count > Highϋmit ) Value = 0 ; if ( Value = -1 ) return 1 ; for ( i = Top ; i < Bottom ; i++ ) { for ( j = Left ; j < Right ; j++ ) { BITMAP_PLACE(Target,i l j) = Value ; } } return 1 ; } 335 T RULE 2ϋ) /* int qrsolv(M,size,b) * Solves the linear system : Mx = b using the QR Decomposition. * On output b is overwritten by the solution x. * Algorithm : * 1 )qrdecomp M into Q & R (coded in M,m1 ,m2). * 2)multiply b by Q(transpose). * 3)R.solve Rx=Q(transpose)b. * C Implementaion: Dr. I. Wilf . */ #define ORDER 8 #include<math.h> #include "qrsolv.h" int qrsoiv (m, size, b) double mfORDERjfORDER]; int size ; double bfORDERJ; { int i, j; double tau, mlfORDERj, m2[ORDERj; if (qrdecomp (m, size, ml , m2) < 0) return 0 ; //error ("singularity in qrdecomp()\n"); for (j = 0; j < (size - 1); j++) { tau = 0; for (i = j; i < size; i++) tau += rnpjTj] * bfij; tau /= m1 " ]; for (i = j; i < size: i++) b[i] -= tau * m[i]0j; } bfsize - 1j /= m2[size - 1 j; 3Αlc rsolv (m, size, m2, b); } / * * Compute the QR decomposition of a square matrix m using the Stewart * algorithm. * Upon termination , thr decomposition is stored in m,m1 and m2 as * follows: * R is contained in the upper triangle of m except that its main * diagonal is contained in m2, and Q(transpos)=Q(n-1)*...*Q(1) * where Q(j)=l-(Uj*Uj(transpos)/Pj) where * Stewart, G.W., Introduction to matrix Computations , Academic Press, New York (1973). * C Implemeπtaion: Dr. I. Wilf. int qrdecomp (m, size, ml , m2) double m[ORDER][ORDERJ; double mlfORDER], m2[ORDERj; { 3aη return (-1 ); /* form Qk and premultiply m by it 7 t = 0; for (i = k; i < size; i++) { mfijfkj /= eta; t += mfijfkj * mfijfkj; } if(mfkjfk] >= 0.0) sigma = sqrt(t); else sigma = -sqrt(t).; mfkjfk] += sigma; m1fkj = sigma * m[kj[kj; m2fk] = (-eta * sigma); tau = 0; for (j = k + 1 ; j < size; j++) { tau = 0; for (i = k; i < size; i++) tau += mfijfkj * mp]Q]; tau /= m1[kj; for (i = k; i < size; i++) mfiJOJ -= tau * mfijfkj; } } m2fsize - 1 j = mfsize - 1 jfsize - 1j; return (0); } / * * rsolv(m,size,m2.b) * solve Rx=b for b, where the upper triangular matrix R is * stored in M , m2. * C Implementaion: Dr. I. Wilf. 7 rsolv (m, size, m2, b) double mfORDERJfOROERj; double m2[ORDER], 3SX bfORDERj; { int i, j; double s; for (i = size - 2; i >= 0; i-) { s = 0; for (j = i + 1 ; j < size; j++) s += mfiJD] * bfjj; b[i] = (bfi]-s)/m2[ij; } } 3a c . #include <windows.h> #include <windowsx.h> #include <commdlg.h> #include <stdlib.h> #include <bios.h> #include "consLh" #include "bitmap.h" #include "persp.h" #include "lines.h" #include "track.h" #include "min.mag.h" #include "lib.h" int PASCAL l.cp_int_arr_to.RPOINT(RPOINT * Rpoint, int * ArrX, int *ArrY,int num) { int i ; for ( i = 0 ; i < num ; i++ ) { Rpointfi].x = ArrXfi] ; Rpointpj.y = ArrYIi] ; } return 1 ; } int PASCAL l.quad_in_new_origin(RPOINT *NewQuad,RPOINT *Quad, int Xorg.int Yorg.int num) { int i ; for ( i = 0 ; i < num ; i++ ) { NewQuadfij.x = Quadfij.x-Xorg ; NewQuadfij.y = Quadfij.y-Yorg ; } return 1 ; } int PASCAL l_copy.RPOINT.array(RPOINT To.RPOINT * From,int num) { int i ; for ( i = 0 ; i < num ; i++ ) { Tofij = Fromfi] ; } return 1; } int PASCAL l_copy_int.array(int To, int * From,int num) { int i ; for ( i = 0 ; i < num ; i++ ) { Tofij = Fromfi] ; } return 1 ; } int PASCAL l_fιnd.bound_rect(RPOINT * Vertexes, RECT *Rectan) { Rectan->left =(int)min(min(min(VertexesfO].x,Vertexes[1].x),Vertexes[2].x),Vertexesf3j.x) ; Rectan->top = (int)min(min(min(Vertexesf0j.y,Vertexes[1].y),Vertexesf2j.y),Vertexesf3].y) ; Rectan->right =(int)max(max(max(Vertexes[0].x,Vertexes[1j.x),Vertexesf2].x),Vertexes[3].x) ; Rectan->bottom = (int)max(max(max(Vertexes[0j.y,Vertexes[1].y),Vertexes[2j.y),Vertexesf3].y) ; return 1 } 33I int PASCAL find_extremes_in.1dim(RP0INT "Points, int Number, int Dim, double • MaxVal, double * MinVal) { int i ; double MaxNum, MinNum ; if ( Dim == X.DIM ) { MaxNum = MinNum = PointsfOj.x ; for ( i = 1 ; i < Number ; i++ ) { if ( Pointsfij.x > MaxNum ) { MaxNum = Pointsfij.x ; continue ; } if ( Pointsfij.x < MinNum ) { MinNum = Pointsfij.x ; continue ; } } *MaxVal = MaxNum ; *MinVal = MinNum ; } if ( Dim == Y_DIM ) { MaxNum = MinNum = PointsfOj.y ; for ( i = 1 ; i < Number ; i++ ) { if ( Pointsfij.y > MaxNum ) { MaxNum = Pointsfij.y ; continue ; } if ( Pointsfij.y < MinNum ) { MinNum = Pointsfij.y ; continue ; } } • MaxVal = MaxNum ; *MinVal = MinNum ; } return 1 ; } int PASCAL find_best.cluster(HWND hwnd, int Number, RPOINT * Points, RPOINT *Cluster,int *NumCluster,int Dim, int *lndexes,int *Clustlndex,RPOINT * NotCluster, int * Notlndexes) { int i,j,k ; int Count,NCount ; int Distance ; int Range ; double MaxNum.MinNum ; int * DistArray ; double * SumArray ; double MaxSum ; double MaxNumbers, Value ; int Maxlndex ; if ( Number == 0 ) return 0 ; fιnd_extremes_in.1dim(Points,Number,Dim,&MaxNum,&MinNum) ; Range = (int)(fabs(MaxNum - MinNum+0.5)) ; DistArray = (int *) GlobalAllocPtr (GMEM_MOVEABLE, (DWORD)sizeof(int)*(DWORD)Number*(DWORD)Range ) ; SumArray = (double * ) GlobalAllocPtr (GMEM_MOVEABLE, (DWORD)sizeof(double) * (DWORD)Number) ; for ( i = 0 ; i < Number ;i++ ) { SumArrayfi] = 0.0 ; for ( j = 0 ; j < Range ; j++ ) { VALUE_IN(DistArray,i,j, Range) = 0 ; } } for ( i = 0 ; i < Number ; i++ ) { for ( j = 0 ; j < Number ; j++ ) { if ( i == j ) continue ; for ( k = 1 ; k <= Range ; k++ ) { if ( Dim == X.DIM ) { if ( fabs(PointsO].x - Pointsfi].x)<= (double)k ) { VALUE_IN(DistArray,i,k-1, Range) += 1 ; } } else { if ( fabs(Pointsfj].y - Points[i].y)<= (double)k ) { VALUE_IN(DistArray,i,k-1.Range) += 1 ; } } } } } MaxSum = 0.0 ; Maxlndex = 0 ; for ( i = 0 ; i < Number ; i++ ) { for ( j = 0 ; j < Range ; j++ ) { SumArrayf ij += (double)(VALUE JN(DistArray,.,j,Range))/(double)(j+1 ); } if ( SumArrayfij > MaxSum ) { Maxlndex = i ; MaxSum = SumArrayfi] ; } } MaxNumbers = 0.0 ; for ( i = 0 ; i < Range ; i++ ) { Value = (double)(VALUE_IN(DistArray,Maxlndex,i,Range))/(double)(i+1) ; if ( Value > MaxNumbers ) { MaxNumbers = Value ; Distance = i+1 ; } } if ( Range == 1 && MaxNumbers <= 2 ) { GlobalFreePtr(SumArray) ; GlobalFreePtr(DistArray) ; return 0 ; 33^ } if ( Range > 1 && MaxNumbers < (double)Number/((double)Range+0.01 ) ) { GlobalFreePtr(SumArray) ; GlobalFreePtr(DistArray) ; return 0 ; } Count = NCount = 0 ; for ( j = 0 ; j < Number ; j++ ) { if ( Dim == X.DIM ) { if ( fabs(Points[jj.x - Points[Maxlndex].x)<= (double)Distance ) { ClusterfCountj = Pointsfjj ; ClustlndexfCount++] = Indexesfj] ; } else { NotClusterfNCountj = Pointsfjj ; Notlndexes[NCount++] = Indexesfjj ; } } else { if ( fabs(Points[jj.y - PointsfMaxlndex].y)<= (double)Distance ) { ClusterfCountj = Pointsfjj ; Clustlndex[Count++j = IndexesOJ ; } else { NotClusterfNCountj = Pointsfjj ; Notlndexes[NCount++] = Indexesfj] ; } } } • NumCluster = Count ; GlobalFreePtr(SumArray) ; GlobaΙFreePtr(DistArray) ; return 1 ; } int PASCAL print Jransform(HFILE hFile.char * Head, Perspective.Transform * TP) { 33:". int j ; char Str ing[50] ; Jwrite(hFile,Head,strlen(Head)) ; for ( j = 0 ; j < 3 ; j++ ) { sprintf(Sthng,"\n%lf, %lf, %lf\n",Tp->Pf[j][0], Tp->PfD][1],Tp->PfD ' P]) ; _lwrite(hFile,String,strlen(String)) ; } return 1 ; } int PASCAL insert.new.vertexes(RPOINT *CurrVert, RPOINT * Vert1, RPOINT * Vert2, RPOINT *Vert3, RPOINT *Vert4,double *WheighLint num.RPOINT • NewVert) { int i ; RPOINT Delta[4] ; double Sum ; Sum = WheightfO] + Wheightfl ] + Wheight[2] ; for ( i = 0 ; i < num-1 ; i++ ) { Vert1[i] = Vert1fi+1j ; Vert2fij = Vert2[i+1] ; Vert3fi] = Vert3fi+1] ; Vert4fi] = Vert4[i+1] ; } Vert1[num-1] = CurrVertfO] ; Vert2[num-1] = CurrVertfl] ; Vert3fnum-1] = CurrVertf2] ; Vert4fnum-1] = CurrVert[3] ; for ( i = 0 ; i < num-1 ; i++ ) { Deltafij.x = Vert1[i+1].x - Vert1[i].x ; Deltafij.y = Verti [i+1 ].y - Vertl fi].y ; } 33b Delta[2].x =(Delta[2].x*Wheightf2j + Delta[1].x * Wheight[1j + Delta[0].x*Wheight[0])/Sum ; Delta[2].y =(Delta[2j.y*Wheightf2j + Delta[1].y * Wheight[1j + Delta[0].y*Wheight[0])/Sum ; NewVertfOj.x = Vertl [2j.x + Delta[2].x ; NewVertfOj.y = Vertl [2j.y + Delta[2]. ; for ( i = 0 ; i < num-1 ; i++ ) { Deltafi].x = Vert2[i+1].x - Vert2fi].x ; Deltafij.y = Vert2[i+1 j.y - Vert2[ij.y ; } Deltaf2].x =(Deltaf2].x*Wheight[2j + Delta[1].x * Wheight[1] + DeltafOj.x*WheightfO])/Sum ; Deltaf2j.y =(Deltaf2].y * Wheight[2j + Delta[1].y * Wheight[1] + Delta[0].y*Wheight[Oj)/Sum ; NewVert[1].x = Vert2f2].x + Deltaf2].x ; NewVertf y = Vert2[2j.y + Delta[2].y ; for ( i = 0 ; i < num-1 ; i++ ) { Deltafij.x = Vert3fi+1].x - Vert3[i].x ; Deltafij.y = Vert3fi+1].y - Vert3fi].y ; } Delta[2j.x =(Delta[2].x * Wheightf2] + Delta[1].x*Wheightf1] + Delta[0].x*Wheight[O])/Sum ; Deltaf2j.y =(Delta[2].y * Wheight[2] + Delta[1].y * Wheightf1] + Delta[Oj.y*Wheight[0])/Su ; NewVertf2].x = Vert3[2j.x + Delta[2].x ; NewVertf2].y = Vert3f2j.y + Deltaf2].y ; for ( i = 0 ; i < num-1 ; i++ ) { Deltafij.x = Vert4fi+1 j.x - Vert4[i].x ; Deltafij.y = Vert4[i+1 j.y - Vert4fi].y ; } Deltaf2].x =(Delta[2].x * Wheight[2] + Delta[1].x * Wheight[1] + Delta[0].x * WheightfO])/Sum ; Deltaf2j.y =(Deltaf2j.y * Wheightf2] + Delta[1].y * Wheightf1] + DeltafOj.y * Wheight[0])/Su ; NewVert[3j.x = Vert4f2].x + Delta[2].x ; NewVert[3j.y = Vert4[2].y + Delta[2].y ; return 1 ; } t int PASCAL transform_rpoint.arr(RPOINT *SrcPnts, RPOINT * DstPnts, int num .Perspective.Transform TpCurr ) { double DstX,DstY,w ; int i ; for ( i = 0 ; i < num ; i++ ) { DstX = SrcPntsfij.x * TpCurr. Pf[0][0j + SrcPntsfij.y * TpCurr. Pff1][0] + TpCurr.Pff2][0] ; DstY = SrcPntsfi].x * TpCurr. PffOjfl] + SrcPntsfij.y *TpCurr.Pff1][1 ] + TpCurr.PfI2][1] ; w = SrcPntsfij.x * TpCurr. Pf[0]f2] + SrcPntsfij.y * TpCurr. Pff1][2] + TpCurr. Pff2]f2] ; DstPntsfij.x = DstX/w ; DstPntsfij.y = DstY/w ; } return 1 ; } 33 % #include <windows.h> #include <windowsx.h> #include <commdlg.h> #include <stdlib.h> #include "const.h" #irτclude "bitmap.h" #include "lines.h" #include "track.h" #include "persp.h" #include "min.mag.h" #include "lib.h" int PASCAL improve_diff.bmap(MYBITMAP *,MYBITMAP * ) ; int PASCAL copy.rect_bmap(int ,int .MYBITMAP • .MYBITMAP *); int PASCAL perspective(HWND hwnd.MYBITMAP FAR • SrcBmap, MYBITMAP FAR *DstBmap, RPOINT * SrcPnts.RPOINT * DstPnts.int ColorModel, Perspective.Transform Tp) { //Rectan2Quad(hwnd,SrcPnts, DstPnts.Tp); Quad2Quad(hwnd,SrcPnts, DstPnts.Tp); Perspective.map(SrcBmap, Tp, DstBmap, DstPnts, ColorModel); return TRUE ; } int PASCAL perspective_near(HWND hwnd.MYBITMAP FAR *SrcBmap, MYBITMAP FAR *DstBmap, RPOINT* SrcPnts.RPOINT * DstPnts.int ColorModel, Perspective_Transform Tp) { //Rectan2Quad(hwnd,SrcPnts, DstPnts.Tp); Quad2Quad(hwnd,SrcPnts, DstPnts.Tp); Perspective_near.maρ(SrcBmaρ, Tp, DstBmap, DstPnts, ColorModel); 331 return TRUE ; int PASCAL Rectan2Quad(HWND hwnd, RPOINT * src_pts, RPOINT *dst_pts, Perspective.Transform Tp) { double xO, yO, x1 , y1 , x2, y2, x3, y3; double dx1 , dy1 , dx2, dy2, dx3, dy3; double denom ; double a11, a12, a13, a21, a22, a23, a31, a32, a33; double Af3][3j, B[3][3]; /* Verify that src_pts do form a rectangle 7 if ( check_if_rect(src_pts) == FALSE ) { MessageBox (hwnd, "Source is not a rectangle", "Perspective trans.", MB.ICONEXCLAMATION | MB.OK) return NULL ; } /* Solve for transformation from f(0,0),(1 ,1 )] -> Quad 7 xO = dst.pts[0].x; yO = dst.pts[0].y; x1 = dst_pts[1].x; y1 = dst_pts[1].y; x2 = dst.ptsf2].x; y2 = dst_pts[2].y; x3 = dst_ptsf3].x; y3 = dst.pts[3j.y; dx1 = x1 - x2; dy1 = y1 - y2; dx2 = x3 - x2; dy2 = y3 - y2; dx3 = xO - x1 + x2 - x3; dy3 = yO - y1 + y2 - y3; 3 /* if dx3 = dy3 = 0: transformation is affine 7 /* otherwise: transformation is perspective 7 / * * Forward transformation: * [χ_.y_. j = fu,v,i] Pf * where: |a11 a12 a13| Pf = |a21 a22 a23| |a31 a32 a33| * Then: fx, yj = [x_/w_, y_/w 7 denom = det2(dx1 , dx2, dy1 , dy2); a13 = det2(dx3, dx2, dy3, dy2) / denom; a23 = det2(dx1 , dx3, dy1 , dy3) / denom; a11 = x1 - x0 + a13 * x1; a21 = x3 - xO + a23 * x3; a31 = xO; a12 = y1 - y0 + a13 * y1; a22 = y3 - yO + a23 * y3; a32 = yO; a33 = 1.0; { Af0]f0] = a11; A[0][1] = a12; Af0][2j = a13; A[1]f0j = a21; A[1][1] = a22; A[1][2] = a23; Af2][0] = a31; Af2][1] = a32; Af2]f2] = a33; } 3^ | /* pre-multiply by the matrix converting src_pts->[(0,0),(1 ,1 )] 7 { double xs = src.ptsf0j.x; double ys = src.ptsfO].y; double xe = src_pts[2].x; double ye = src_ρtsf2].y; double dx = xe - xs; double dy = ye - ys; B[0]f0j = 1.0 / dx; B[1]f0] = 0.0; Bf2][0] = -xs / dx; Bf0][1j = 0.0; Bf1][1] = 1.0 / dy; B[2][1] = -ys / dy; B[0][2] = 0.0; B[1]f2] = 0.0 Bf2][2] = 1.0 multmat(hwnd,3, 3, 3, (double * )B, (double*)A, (double * )(Tp->Pf)); } / * * Backward transformation: * [u_,v.,wj = fx,y,1] Pb * where: |A11 A12 A13| Pb = |A21 A22 A23| |A31 A32 A33| * * is the inverse of Pf. * * Then: fu, vj = [u_/w_, v_/w 7 { a11 = Tp->Pf[0][0]: a12 = Tp->Pf[0]f1] a13 = Tp->Pf[0][2] 3^A ' a21 =Tp->Pf[1][0] a22 = Tp->Pff1][1] a23 = Tp->Pff1][2] a31 = Tp->Pff2]f0j a32 = Tp->Pf[2][1] a33 = Tp->Pf[2][2] } Tp->Pb[0][0] : a22 * a33 ■ a23 * a32 Tp->Pb[0][1] a13 * a32 -a12*a33 Tp->PbfO][2] a12*a23 ■ a13*a22 Tp->Pb[1][0] ■ ■ a23 * a31 • a21 * a33 Tp->Pb[1][1] : a11 *a33 ■ a13 * a31 Tp->Pbf1]f2] a13 * a21 ■a11 *a23 Tp->Pb[2][0j : a21 * a32 • a22 * a31 Tp->Pbf2][1] = a12*a31 a11 *a32 Tp->Pb[2][2] = a11 * a22^ a12*a21 return 1 ; } int PASCAL Quad2Rectan(HWND hwnd, RPOINT *src_pts, RPOINT *dst_pts, Perspective_Transform Tp) { double Tmp ; Rectan2Quad(hwnd,dst_pts,src.pts,Tp) ; Tmp = Tp->PfI0][0] ; Tp->Pf[0][0] = Tp->PbfO][0] ; Tp->PbfO][0] = Tmp ; Tmp = Tp->Pff0][1]; Tp->PffO]f1] =Tp->PbfO][1]; Tp->Pbf0][1] = Tmp; Tmp = Tp->PfI0][2] ; ?> 3 Tp->Pf[0][2] = Tp->Pb[0j[2] ; Tp->Pb[0][2j = Tmp ; Tmp = Tp->Pf[1][0j; Tp->Pf[1][0] =Tp->Pb[1jf0j; Tp->Pb[1][0] = Tmp; Tmp = Tp->PfI1][1j; Tp->Pff1]f1] =Tp->Pbf1]f1j; Tp->Pb[1]f1] = Tmp; Tmp = Tp->Pff1]f2]; Tp->Pf[1][2] =Tp->Pb[1][2]; Tp->Pb[1][2] = Tmp; Tmp = Tp->Pff2]f0j; Tp->Pf[2][0] = Tp->Pbf2][0] ; Tp->Pb[2]fO] = Tmp ; Tmp = Tp->Pf[2][1]; Tp->Pff2]f1] =Tp->Pb[2][1j; Tp->Pbf2][1] = Tmp; Tmp = Tp->Pff2]f2] ; Tp->PfI2]f2J =Tp->Pb[2]f2j; Tp->Pb[2]f2] = Tmp ; return 1; } int PASCAL check_if_rect(RPOINT * Points) { if ( PointsfOj.x != Pointsf3].x ) return FALSE if ( Pointsfij.x != Pointsf2].x ) return FALSE if ( PointsfOj.y != Pointsfij.y ) return FALSE if ( Points[2].y != Pointsf3j.y ) return FALSE 5-~ return TRUE ; } int PASCAL Perspective_near_map(MYBITMAP • src.bmap, Perspective.Transform * Tp, MYBITMAP *dst_bmap, RPOINT * dst_pts, int ColorModel) { RECT r, Screen; DWORD i, j; DWORD Size ; BYTE huge *Ptr ; double RcBil ; int Colsmin1 ,Rowsmin1 ; double y.dst ; double x.dst ; RPOINT uv, xy; double D ; BYTE huge *Colors ; int uy.ux ; / * Find bounding rectangle of dst.pts 7 l_find_bound_rect(dst_pts, &r) ; Colsminl = src_bmap->cols -1 ; Rowsminl = src.bmap->rows -1 ; Colors = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,3) ; for (i = r.top; i < r.bottom; i++) { y_dst = (double) i; for (j = r.left; j < r.right; j++) { x_dst = (double) j; D = 1.0; xy.x = x.dst; xy.y = y.dst; uv = bPerspective(xy, Tp); if (uv.x < 0.0 || uv.x >= (double) (src_bmap->cois-1 )) 3-tS continue; if (uv.y < 0.0 || uv.y >= (double) (src_bmap->rows-1 )) continue; uy = (int)(uv.y+0.5) ; ux = (int)(uv.x+0.5) ; if ( ColorModel == GREY.MODEL ) { RcBil = BITMAP_PLACE(src_bmap,uy,ux) ; BITMAP_PLACE(dst_bmap,i.j) = (BYTE)RcBil ; } else { // COLOR.MODEL Ptr = B_TMAP_RGB_PLACE.PTR(dsLbmap.ij) ; Colors = BITMAP_RGB_PLACE.PTR(src.bmap,uy,ux) ; PtrfOj = (BYTE)ColorsfOj Ptr[1] = (BYTE)Colors[1] Ptrf2j = (BYTE)Colorsf2j } } GlobalFreePtr(Colors) ; return (0); int PASCAL Perspective_map(MYBITMAP FAR • src.bmap, Perspecti ve.Transf orm* Tp, MYBITMAP FAR * dst_bmap, RPOINT *dst_pts,int ColorModel) { RECT r, Screen; DWORD i, j; DWORD Size ; BYTE huge *Ptr ; double RcBil ; int Colsmin1,Rowsmin1 ; double y.dst 3^lo /* Find bounding rectangle of dst.pts 7 l_find_bound_rect(dst.pts, &r) ; Colsminl = src_bmap->cols -1 ; Rowsminl = src_bmap->rows -1 ; for (i = r.top; i < r.bottom; i++) { y.dst = (double) i; for 0 = r.left; j < r.right; j++) { x.dst = (double) j; D = 1.0; xy.x = x.dst; xy.y = y.dst; uv = bPerspective(xy, Tp); if (uv.x < 0.0 || uv.x >= (double) (src_bmap->cols)) continue; if (uv.y < 0.0 || uv.y >= (double) (src_bmap->rows)) continue; if ( ColorModel == GREY.MODEL ) { RcBil = (BYTE)bilinear(uv.x,uv.y, src.bmap); if ( RcBil == -1.0 ) continue ; BITMAP_PLACE(dst_bmap,i,j) = (BYTE)RcBil ; } else { // COLOR.MODEL Ptr = BITMAP_RGB.PLACE_PTR(dst_brτ.ap,i.j) ; bilinear_rgb(uv.x,uv.y,src_bmap, Colors) ; PtrfO] = (BYTE)ColorsfOj Ptr[1] = (BYTE)Colors[1] Ptr[2j = (BYTE)Colorsf2j } } } return (0); } RPOINT bPerspective(RPOINT xy, Perspective.Transform Tp) { RPOINT uv; double x = xy.x; double y = xy.y; double u_ = x * Tp->Pb[0][0] + y * Tp->Pb[1][0j + Tp->Pbf2]f0j; double v. = x * Tp->Pb[0][1 j + y * Tp->Pb[1][1 j + Tp->Pbf2][1 j; double w_ = x * Tp->PbfO][2] + y * Tp->Pb[1]f2j + Tp->Pbf2][2j; uv.x = u_ / w_; uv.y = v. / w_; return (uv); RPOINT PASCAL fPersρective(RPOINT xy, Perspective.Transform Tp) { RPOINT uv ; double x = xy.x; double y = xy.y; double u_ = x * Tp->Pf[0][0] + y * Tp->Pff 1 ]f0j + Tp->Pf[2]fO]; double v. = x * Tp->Pf[0][1 ] + y * Tp->PfI1 ][1 j + Tp->PfI2][1 ]; double w_ = x * Tp->Pf[0][2] + y * Tp->Pff1 ]f2] + Tp->Pff2][2]; uv.x = u. / w_; uv.y = v_ / w_; return (uv); double PASCAL dPerspective(RPOINT xy, Perspective.Transform Tp) { double Du, Dv, D; double Dux, Duy; double Dvx, Dvy; double x = xy.x; double y = xy.y; 3^ double u_ = x * Tp->Pbf0][0j + y * Tp->Pb[1 ][0] + Tp->Pbf2]f0j; double v. = x * Tp->Pb[0j[1 ] + y * Tp->Pb[1 ][1 j + Tp->Pb[2][1 ]; double w_ = x * Tp->Pb[0][2] + y * Tp->Pbf 1 ][2] + Tp->Pb[2][2j; double u.x = Tp->Pb[0]fO] double u_y = Tp->Pb[1][0] double v.x = Tp->Pb[0]f1] double v_y = Tp->Pbf1][1] double w_x = Tp->PbfO]f2] double w_y = Tp->Pb[1 ]f2] Dux = (u.x * w_ - u. * w.x) / (w. * wj; Duy = (u_y * w_ - u. * w_y) / (w. * w_); Du = sqrt(Dux * Dux + Duy * Duy); Dvx = (v_x * w. - v. * w.x) / (w. * w ; Dvy = (v_y * w_ - v. * w_y) / (w. * w ; Dv = sqrt(Dvx * Dvx + Dvy * Dvy); D = max(Du, Dv); return (D); #defιne MEDIAN.EDGE 5 #defιne MEDIAN.SIDE 2 int PASCAL median.filter_5(HWND hwnd.MYBITMAP * Bmap) { int i, j ,k,l,n; int MedVec[MEDIAN_EDGE*MEDIAN_EDGE] ; BYTE lndexArr[256] ; int Median ; MYBITMAP TmpBmap ; BYTE huge TmpPtr ; BYTE huge * BmapPtr ; DWORD Size, PI ; DWORD FromTime.ToTime ; char String[100J ; int Sum ; int RowLimit , ColLimit ; TmpBmap = bm_alloc(Bmap->cols,Bmap->rows,GREY_MODEL) ; Size = (DWORD)Bmaρ->cols*(DWORD)Bmap->rows ; TmpBmap->gpic = (BYTE huge*)GlobalAllocPtr(GMEM.MOVEABLE,Size) ; BmapPtr = Bmap->gpic ; TmpPtr = TmpBmap->gpic ; for ( PI = 0 ; PI < Size ; PI++ ) { *(TmpPtr++) = *(BmapPtr++) ; } for ( i = 0 ; i < Bmap->rows ; i++ ) { for ( j = 0 ; j < Bmap->cols ; j++ ) { if ( BITMAP_PLACE(TmpBmap,i,j) <= 24 ) { BITMAP_PLACE(TmpBmap,i,j) = 0 ; } } } WriteGreyRgb (hwnd,"no48.rgb",TmρBmap) ; //FromTime = GetTickCount() ; RowLimit = Bmap->rows -3 ; for ( i = 2 ; i < RowLimit ; i++ ) { for ( k = 0 ; k < 256 ; k++ ) IndexArrfkj =0 ; for (j = 0 ; j < 5 ; j++ ) { lndexArrfBITMAP_PLACE(TmpBmap,i-2,j)] += 1 ; lndexArr[BlTMAP_PLACE(TmpBmap,i-1,j)j += 1 ; lndexArτfBITMAP.PLACE(TmpBmaρ,i,j)] += 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i+1,j)] += 1 ; lndexArr[BITMAP_PLACE(TmpBmap,i+2,j)j += 1 ; } for ( Sum = k = 0 ; k < 256 ; k++ ) { Sum += IndexArrfkj ; if ( Sum >= 13 ) { 350 ^ BITMAP_PLACE(TmpBmap,i.2) = k ; break ; } } ColLimit = Bmap->cols - 3; for ( j = 3 ; j < ColLimit ; j++ ) { IndexArr[BITMAP_PLACE(TmpBmap,i-2,j-3)j -= 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i-1 ,j-3)j - 1 ; lndexArr[BITMAP_PLACE(TmpBmap,i,j-3)j -= 1 ; lndexArrfBITMAP_Pl__ACE(TmpBmap,i+1 ,j-3)] -= 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i+2.j-3)j -= 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i-2,j+2)j += 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i-1 ,j+2)j += 1 ; indexArrfBITMAP_PLACE(TmpBmap,i,j+2)j += 1 ; lndexArrfBITMAP_PLACE(TmpBmap,i+1,j+2)j += 1 ; lndexArrfBITMAP.PLACE(TmpBmap,i+2j+2)] += 1 ; for ( Sum = k = 0 ; k < 256 ; k++ ) { Sum += IndexArrfk] ; if ( Sum >= 13 ) { BITMAP_PLACE(TmpBmap,i,j) = k ; break ; } } } } WriteGreyRgb (hwnd,"med5.rgb",TmpBmap) ; //ToTime = GetTickCount() ; //sprintf(String,"Time elapsed = %lu",ToTime-FromTime) ; //MessageBox (hwnd, String,"Median Calc", MBJCONEXCLAMATION MB.OK) ; improve.diff.bmap(Bmap,TmpBmap) ; bm_free(TmpBmap) ; return 1; } int PASCAL improve diff_bmap(MYBITMAP *Bmap,MYBITMAP TmpBmap) 55 { int ij ; int ICount,JCount ; int Frj ; int Limit ; int Cols, Rows ; Frj = 0 ; JCount = 0 ; Cols = Bmap->cols ; Rows = Bmap->rows ; Limit = Bmap->rows / 8 ; for ( j = 0 ; j < Cols ; j++ ) { ICount = 0 ; for ( i = 0 ; i < Rows ; i++) { if ( BITMAP_PLACE(TmpBmap,i,j) != 0 ) ICount++ ; } if ( ICount < Limit ) JCount++ ; else { if ( JCount > 0 ) { • copy.rect_bmap(Frj,JCount,TmpBmap,Bmap) ; JCount = 0 ; } Frj = j+1 ; } } return 1 ; } int PASCAL copy.rect.bmap(int FromCoI.int NumCols.MYBITMAP *From,MYB_TMAP To) { int i, j ; int Until ; Until = FromCol + NumCols ; for ( j = FromCol ; j < Until ; j++ ) { 35σ. for ( i = 0 ; i < From->rows ; i++ ) { BITMAP_PLACE(To,i,j) = BITMAP_PLACE(From,i,j) ; } } return 1 ; } int PASCAL get_treshJor_occ(MYBITMAP *Bmap,int Tresh) { DWORD Size,n ; BYTE huge TmpPic ; DWORD lndexArrf256j ; int i ; DWORD Sum, MidSize ; for ( i = 0 ; i < 256 ; i++ ) { IndexArrfij = 0 ; } Size = (DWORD)(Bmap->cols)*(DWORD)(Bmap->rows) ; TmpPic = Bmap->gpic ; for ( n = 1 ; n < Size ; n++ ) { lndexArr[ * (TmpPic++)j += 1 ; } Midsize = Size/2 ; Sum = 0 ; for ( i = 0 ; i < 256 ; i++ ) { Sum += IndexArrfij ; if ( Sum >= MidSize ) { Tresh = i ; break ; } } if ( Tresh < 32 ) Tresh = 32 ; return 1 ; } int PASCAL perspective_mask(HWND hwnd.MYBITMAP • SrcBmap.MYBITMAP *DstBmap, MYBITMAP * Alpha,RPOINT * SrcPnts, RPOINT * DstPnts, int ColorModel, int interpolation, MYBITMAP * MaskBmap) { Perspective_Transform Tp ; //Rectan2Quad(hwnd,SrcPnts, DstPnts,&Tp); Quad2Quad(hwnd,SrcPnts, DstPnts,&Tp); Perspective_map_mask(SrcBmap, &Tp, DstBmap, Alpha, DstPnts, ColorModel, interpolation.MaskBmap); return 1 ; } int PASCAL Perspective_map.mask(MYBITMAP FAR *src.bmap, Perspective.Transform * Tp, MYBITMAP FAR *dst_bmap, MYBITMAP * Alpha.RPOINT *dst_pts,int ColorModel, int interpolation.MYBITMAP *MaskBmap) { RECT r, Screen; DWORD i, j; DWORD Size ; BYTE huge * Ptr ; double RcBil ; double Coiors[3] ; int AiphaNumber ; /* Find bounding rectangle of dst_pts 7 l.find.bound.rect(dst.pts, &r) ; for (i = r.top; i < r.bottom; i++) { double y_dst = (double) i; for (j = r. left; j < r. right; j++) { double x.dst = (double) j; RPOINT uv, xy; double D = 1.0; xy.x = x.dst; xy.y = y.dst; uv = bPerspective(xy, Tp); if (uv.x < 0.0 || uv.x >= (double) (src.bmap->cols)) continue; if (uv.y < 0.0 || uv.y >= (double) (src.bmap->rows)) continue; if ( ColorModel == GREY.MODEL ) { RcBil = (BYTE)bilinear(uv.x,uv.y, src.bmap); if ( RcBil == -1.0 || BITMAP_PLACE(MaskBmap,i-r.top,j-r.left) = 0 ) continue ; BITMAP.PLACE(dst_bmap,i,j) = (BYTE)RcBil ; } else { // COLOR.MODEL Ptr = BITMAP_RGB_PLACE_PTR(dst_bmap,i,j) ; RcBil = bilinear.rgb(uv.x,uv.y,src.bmap,Colors) ; if ( RcBil == -1.0 || BITMAP_PLACE(MaskBmap,i-r.top,j-r.left) == 0) continue if (BITMAP_PLACE(MaskBmap,i-r.top,j-r.left) == 2 ) { PtrfO] = (BYTE)((double)((DWORD)Colors[0] * (DWORD)128 + (DWORD)Ptr[0] * (DWORD)128)/256.0) ; Ptr[1] = (BYTE)((double)((DWORD)Colorsf1] * (DWORD)128 + (DWORD)Ptrf1] * (DWORD)128)/256.0) ; Ptr[2] = (BYTE)((double)((DWORD)Colors[2j * (DWORD)128 + (DWORD)Ptr[2] * (DWORD)128)/256.0) ; continue ; } AlphaNumber = BITMAP_PLACE(Alpha,i,j) ; if ( AlphaNumber > 1 ) { PtrfO] = (BYTE)((double)((DWORD)Colors[0j * (DWORD)(256- AlphaNumber) + (DWORD)Ptr[0]*(DWORD)AlphaNumber)/256.0) ; Ptrf1j = (BYTE)((double)((DWORD)Colors[1] * (DWORD)(256- AlphaNumber) + (DWORD)Ptrfl ] * (DWORD)AIphaNumber)/256.0) ; Ptr[2] = (BYTE)((double)((DWORD)Colorsf2] * (DWORD)(256- AlphaNumber) + (DWORD)Ptr[2j * (DWORD)AlphaNumber)/256.0) ; } else { PtrfO] = (BYTE)ColorsfO] Ptr[1] = (BYTE)Colors[1] Ptr[2] = (BYTE)Colors[2j } } } } return (0); } int PASCAL perspective_al(HWND hwnd.MYBITMAP FAR *SrcBmap, MYBITMAP FAR *DstBmap, MYBITMAP * Alpha, RPOINT * SrcPnts.RPOINT * DstPnts.int ColorModel, Perspective_Transform Tp) { //Rectan2Quad(hwnd,SrcPnts, DstPnts.Tp); 3≤ip Quad2Quad(hwnd,SrcPnts, DstPnts.Tp); Perspective.map_al(SrcBmap, Tp, DstBmap, Alpha.DstPnts.ColorModel); return TRUE ; } int PASCAL Perspective_map_al(MYBITMAP • src.bmap, Perspecti ve_Transf orm Tp, MYBITMAP *dst_bmap, MYBITMAP *Alpha,RPOINT * dst_pts,int ColorModel) { RECT r, Screen; DWORD i, j; DWORD Size ; BYTE huge *Ptr ; double RcBil ; int Colsmin1,Rowsmin1 ; double y_dst ; double x.dst ; RPOINT f uv, xy; double D ; double Colorsf3] ; int AlphaNumber ; /* Find bounding rectangle of dst_pts 7 l_fιnd_bound.rect(dst_pts, &r) ; Colsminl = src.bmap->cols -1 ; Rowsminl = src.bmap->rows -1 ; for (i = r.top; i < r.bottom; i++) { y.dst = (double) i; for (j = r.left; j < r.right; j++) { x.dst = (double) j; D = 1.0; xy.x = x.dst; xy.y = y.dst; 357 UBSTITUTE SHEET (RULE 26^ uv = bPerspective(xy, Tp); if (uv.x < 0.0 || uv.x >= (double) (src_bmap->cols)) continue; if (uv.y < 0.0 || uv.y >= (double) (src_bmap->rows)) continue; if ( BITMAP_PLACE(Alpha,i,j) == 0 ) continue ; if ( ColorModel == GREY.MODEL ) { RcBil = (BYTE)bilinear(uv.x,uv.y, src.bmap); if ( RcBil == -1.0 ) continue ; BITMAP_PLACE(dst_bmap,i,j) = (BYTE)RcBil ; J else { // COLOR.MODEL Ptr = BITMAP_RGB_PLACE_PTR(dst_bmap,i,j) ; bilinear.rgb(uv.x,uv.y,src.bmap,Colors) ; AlphaNumber = BITMAP_PLACE(Alpha,i,j) ; if ( AlphaNumber > 1) { PtrfO] = (BYTE)((double)((DWORD)Colors[0] * (DWORD)(256- AlphaNumber) + (DWORD)Ptr[0] * (DWORD)AlphaNumber)/256.0) ; Ptrfl] = (BYTE)((doubie)((DWORD)Colors[1] * (DWORD)(256- AlphaNumber) + (DWORD)Ptrfl ]*(DWORD)AlphaNumber)/256.0) ; Ptrf2] = (BYTE)((double)((DWORD)Colors[2] * (DWORD)(256- AlphaNumber) + (DWORD)Ptr[2] * (DWORD)AlphaNumber)/256.0) ; 352 SUBSTITUTE SHEET (RULE 25) 3S<i #include <windows.h> #include <windowsx.h> #include <commdlg.h> #include <stdlib.h> #include <bios.h> #include "const.h" #include "bitmap.h" #include "persp.h" #include "lines.h" #include "track.h" #include "min.mag.h" #include "lib.h" int PASCAL get_quad_segment.on_x(LINE ,L1NE .double .double -int .RPOINT *) ; int PASCAL mkiine(double x1, double y1, double x2, double y2,LINE *l) { l->a = y2 - y1; l->b = x1 - x2; l->c = -l->a *x1 -l->b *y1; return(1); } int PASCAL mksegment(double x1, double y1, double x2, double y2,SEG *s) { s->a = y2 - y1; s->b = x1 - x2; s->c = -s->a * x1 -s->b * y1 ; s->xmax = max(x1 ,x2) ; s->xmin = min(x1 ,x2) ; s->ymax = max(y1 ,y2) ; s->ymin = min(y1 ,y2) ; return 1 ; 3 tO } int PASCAL get.point_on_segment(SEG s1 , double param, RPOINT *Point) { if ( param < 0.0 || param > 1.0 ) return 0 ; Point->x = param * (s1.xmax-s1.xmin) + sl.xmin ; Point->y = param * (s1.ymax-s1.ymin) + sl.ymin ; return 1 ; } //this function returns in DstPnts the points calculated relative to the //Xparam and YParam always from the minimum. int PASCAL get.shrinked_yquad(RPOINT * SrcPnts, double param, RPOINT • DstPnts) { SEG seg1.seg2.seg3.seg4 ; int i ; for ( i = 0 ; i < 4 ; i++ ) { DstPnts[i].x = SrcPnts[i].x ; DstPntsfij.y = SrcPntsfij.y ; } mksegment(SrcPnts[1].x, SrcPntsf1].y, SrcPnts[2].x, SrcPnts[2].y,&seg2) ; mksegment(SrcPnts[3].x, SrcPnts[3].y, SrcPntsfO].x, SrcPnts[0].y,&seg4) ; if ( get_point_on.segment(seg2, param, &(DstPntsf2])) == 0 ) return 0 ; get_point_on_segment(seg4, param, &(DstPntsf3])) ; return 1 ; } int PASCAL isect.lines(LINE 11, LINE 12, RPOINT * p) { h\ double x,y,w,eps ; X = l1.b*l2.c-I2.b * l1.c; y = l1.c*l2.a-l2.c * H.a; eps = 0.0001 ; if(fabs(w) <= eps) return(O); p->x = x / w; p-> y = y/ ; return(1); } int PASCAL center.of_bounded_rect(RPOINT p1 , RPOINT p2, RPOINT p3, RPOINT p4, RPOINT * Center,double *Xwidth,double * Ywidth) { RPOINT DownCorner.UpCorner ; RPOINT LeftComer.RightComer ; if (p2.y>p1.y){ UpComer.x = p2.x ; UpComer.y = p2.y ; } else { UpComer.x = p1.x ; UpComer.y = p1.y ; } if ( p3.y > p4.y ) { DownComer.x = p4.x ; DownComer.y = p4. ; } else { DownComer.x = p3.x ; DownComer.y = p3.y ; } if ( p1.x>p4.x){ LeftComer.x = pl.x; 36SL LeftComer.y = pl .y ; } else { LeftCorner.x = p4.x ; LeftComer.y = p4.y ; } if ( p2.x > p3.x ) { RightComer.x = p3.x ; RightComer.y = p3.y ; } else { RightComer.x = p2.x ; RightComer.y = p2.y ; } * Xwidth = fabs(RightComer.x - LeftComer.x)/2.0 -2 ; *Ywidth = fabs(UpComer.y - DownComer.y)/2.0 -2 ; Center->x = min(UpComer.x,DownComer.x)+fabs(UpComer.x- DownComer.x)/2.0 ; Center->y = miπ(UpComeF.y,DownComer.y)+fabs(UpCorner.y- DownComer.y)/2.0 ; return 1 ; } // This function gives back the center of each tracking window in the prototype // and the width and height of each window in the transformed model. All // the information is in the Windows array. int PASCAL get_tracking_windows(RPOINT *Prot, RPOINT *Model, int From, int To.TR.WIN * Windows) { double Xmax.Xmin ; double XModmax.XModmin ; double Xunit,XModunit ; double CurrX[20] ; RPOINT Cp1.Cp2.Cp3.Cp4 ; RPOINT Cpf4j ; RPOINT Mo[4] ; int i ; LINE Upϋne.Downϋne ; LINE UpModLine.DownModLine ; RPOINT p1.p2.p3.p4 ; RPOINT mol ,mo2,mo3,mo4 ; RPOINT DumCenterArrf20] ; p1 = ProtfO] ; p2 = Prot[1] ; p3 = Protf2] ; p4 = Protf3j ; mol = ModelfO] ; mo2 = Model[1] ; mo3 = Modelf2] ; mo4 = Model[3] ; Xmax = max(p1.x,p4.x) ; Xmin = min(p2.x,p3.x) ; Xunit = (Xmin-Xmax)/(double)(To-From) ; XModmax = max(mo1.x,mo4.x) ; XModmin = min(mo2.x,mo3.x) ; XModunit = (XModmin-XModmax)/(double)(To-From) ; mkline(ρ1.x,p1.y,p2.x,p2.y,&UpLine) ; mkline(p3.x,p3.y,p4.x,p4.y,&DownLine) ; mkline(mo1.x,mo1.y,mo2.x,mo2.y,&UpModLine) ; mkline(mo3.x,mo3.y,mo4.x,mo4.y,&DownModLine) ; for ( i = From ; i < To-1 ; i++ ) { get_quad_segment_on_x(UpLine, DownLine.Xmax.Xunit.i.Cp) ; center_of_bounded.rect(Cp[0] I Cp[1],Cp[2],Cp[3] I &(Windows[i]. Center), &(Windows[i].Xdir),&(Windows[i].Ydir)) ; get_quad_segment_on_x(UpModLine, DownModLine,XModmax,XModunit,i,Mo) ; center_of_bounded_rect(Mo[0],Mo[1],Mo[2],Mo[3],&(DumCenterArr[i]), &(Windows[i].Xdir),&(Windows[i].Ydir)) ; } 3io-i return 1 ; } // This function gets two horizontal (approx) lines, a start point on // X axis a unit and a number of segment, and returns in Vertexes the // vertexes of a rectangle in the number segment which is bounded inside // these two lines. int PASCAL get_quad.segment_on.x(LlNE UpLine.LINE DownLine.double XStart, double Xunit,int SegNum.RPOINT * Vertexes) { double StartPoint.EndPoint ; StartPoint = XStart + Xunit * SegNum ; EndPoint = StartPoint + Xunit ; VertexesfOJ.y = (UpLine.a*StartPoint + UpLine.c)/-UpLine.b ; Vertexes[0].x = StartPoint ; Vertexes[1].y = (UpLine.a*EndPoint + UpLine.c)/-UpLine.b ; Vertexesflj.x = EndPoint ; Vertexesf2].x = EndPoint ; Vertexes[2].y = (Downϋne.a*EndPoint + DownLine.c)/-DownLine.b ; Vertexes[3].x = StartPoint ; Vertexesf3].y = (DownLine.a * StartPoint + DownLine.c)/-DownLine.b ; return 1 ; } #include < indows.h> #include <windowsx.h> #include <math.h> #include <commdlg.h> #include <stdlib.h> #include "const.h" #include "bitmap.h" #include "lines.h" #include "track.h" #include "persp.h" #include "min.mag.h" #include "lib.h" #define SIZE 8 #define X.AXIS 1 #define Y.AXIS 2 #define MAXIMAL 1 #define MINIMAL 2 static double Faf2 * FSIZE + 1], *F; int PASCAL LSE_Perspective(HWND .SHIFT.POINTS . SHIFT.POINTS .int. Perspective.Transform *) ; int PASCAL xPerspEqn(double , double , double , double *) ; int PASCAL yPerspEqn(double , double , double , double *) ; int PASCAL qrsolvβ (HWND .double mfSlZE][SIZE], int , double *) ; int PASCAL qrdecomp (double mfSIZEjfSIZE], int , double *, double *) ; int PASCAL rsolv (double mfSIZE][SIZE], int , double *, double *) ; int PASCAL invertPerspective(double Pff3][3], double Pbf3]f3]) ; int PASCAL xThinEqn(double, double, double, double *) ; int PASCAL yThinEqn(double, double, double, double *) ; double PASCAL det3(double y[3][3]) ; int PASCAL inv3(double yf3]f3],double zf3][3j) ; int PASCAL tmSim(SHIFT_POINTS , SHIFT.POINTS , int, Perspective.Transform * , HFILE ) ; int cdecl dcomp(const void * a, const void * b) ; 3θ> double norm2(RPOINT a, RPOINT b) ; int PASCAL delete_exterme_point(SHIFT_POINTS .SHIFT.POINTS , int , int ,int * ); MYBITMAP FAR * minify(HWND hwnd.MYBITMAP FAR * in, int fac) { MYBITMAP FAR *aux, * out; /* Build windowed-sine filter-table 7 sinc.filter(fac); /* horizontally sub-sample in -> aux 7 aux = hminify(hwnd, in, fac); I* vertically sub-sample Mid -> Out 7 out = vminify(hwnd,aux, fac); bm.free(aux); retum(out); } MYBITMAP FAR * hminify(HWND hwnd.MYBITMAP FAR * in, int fac) { MYBITMAP FAR *out; int y; int OutCols; int ColorFactor ; OutCols = in->cols / fac ; out = bm_alloc(OutCols , in->rows, in->typ); if(out == NULL) return(NULL); if ( in->typ == COLOR.MODEL ) ColorFactor = 3 ; else ColorFactor = 1 ; 36*7 out->gpic = (BYTE huge * ) GlobalAllocPtr(GMEM_MOVEABLE,(DWORD)OutCols * (DWORD)(in- >rows) * (DWORD)ColorFactor); if(in->typ == GREY.MODEL) { for(y = 0; y < in->rows; y++) { lpf1D(BITMAP_PLACE_PTR(in,y,0), in->cols, fac, BITMAP.PLACE_PTR(out,y,0) ) ; } } else { // COLOR MODEL for(y = 0; y < in->rows; y++) { lpf1 D_rgb(BITMAP_RGB_PLACE_PTR(in,y,0), in->cols, fac, BITMAP_RGB_PLACE.PTR(out,y,0) ) ; } } retum(out); } MYBITMAP FAR * vminify(HWND hwnd.MYBITMAP FAR *in, int fac) { MYBITMAP FAR *out; iπt y, x; BYTE huge *ivec; BYTE huge *ovec; int OutRows ; int ColorFactor ; OutRows = in->rows / fac ; out = bm_alloc(in->cols, OutRows , in->typ); if(out == NULL) return(NULL); if ( in->typ == COLOR.MODEL ) ColorFactor = 3 ; else ColorFactor = 1 ; out->gpic = (BYTE huge * ) 362 . GlobalAllocPtr(GMEM_MOVEABLE,(DWORD)OutRows * (DWORD)(in->cols) < (DWORD)ColorFactor); ivec = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,(DWORD)(in- >rows) * (DWORD)ColorFactor); ovec = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,(DWORD)(out- >rows)* (DWORD)ColorFactor); if(in->typ == GREY.MODEL) { for(x = 0; x < in->cols; x++) { for(y = 0; y < in->rows; y++) ivecfy] = BITMAP_PLACE(in,y,x) ; Ipf1 D(ivec, in->rows, fac, ovec); for(y = 0; y < out->rows; y++) BITMAP_PLACE(out,y,x) = ovecfyj; } } else { for(x = 0; x < in->cols; x++) { for(y = 0; y < in->rows; y++) { ivec[(DWORD)3 * (DWORD)y] = *(BITMAP_RGB_PLACE_PTR(in,y,x)) ; ivecf(DWORD)3 * (DWORD)y+1] = *((B.TMAP_RGB_PLACE_PTR(iπ,y,x))+1 ) ; ivecf(DWORD)3*(DWORD)y+2] = *((BITMAP.RGB_PLACE_PTR(in ) y,x))+2) ; } Ipf1 D_rgb(ivec, in->rows, fac, ovec); for(y = 0; y < out->rows; y++) { *(B ITMAP_RGB.PLACE.PTR(out,y.x)) = ovec[(DWORD)3*(DWORD)y]; • ((BITMAP_RGB_PLACE.PTR(out,y,x))+1 ) = ovec[(DWORD)3*(DWORD)y+1 ]; *((BITMAP_RGB_PLACE_PTR(out,y,x))+2) = ovec[(DWORD)3 * (DWORD)y+2]; } 3 < } } retum(out); } int PASCAL sinc.filter(int fac) { int j; int fsize = LOBES * fac; double pie = acos(-1.0); double sum; F = Fa + fsize; for(j = -fsize; j <= fsize; j++) { FD] = 1.0 / (double)(2 * fsize + 1); } / * Compute windowed sine filter table 7 for(j = -fsize; j <= fsize; j++) { double x = (double)j / fac; double z, w; if(j == 0) { 2 = 1.0; } else { z = sin(pie * x) / (pie * x); } w = 0.5 + 0.5 * cos(pie * (double)j / (double)fsize); F0] = z * w; } /* Normalize to unit integral 7 3'1D for(sum = 0, j = -fsize; j <= fsize; j++) sum += FO]; forQ ' = -fsize; j <= fsize; j++) FO] /= sum; return 1 ; } int PASCAL Ipf1 D(BYTE huge* in, int Dim, int fac, BYTE huge *out) { int i, j, k,x; int dim = Dim / fac; double ace ; for(k = i = 0; i < dim; k += fac, i++) { ace = 0.0; for(j = -2 * fac; j <= 2 * fac; j++) { x = k + j; /* zero padding 7 if(x >= 0 && x < Dim) ace += (double)( * (in+x)) * Fffl; } if(acc < 0.0) *(out+i) = 0; else if(acc > 255.0) * (out+i) = 255; else *(out+i) = (BYTE)(0.5 + ace);; } return 1 ; } int PASCAL ipfl D_rgb(BYTE huge* in, int Dim, int fac, BYTE huge *out) { 311 int i, j, k,x; int dim = Dim / fac; double accr, accg, accb ; DWORD CurrPI ; for(k = i = 0; i < dim; k += fac, i++) { accr = accg = accb = 0.0; for(j = -2 * fac; j <= 2 * fac; j++) { x = k + j; / * zero padding 7 if(x >= 0 && x < Dim) { accr += (double)( * (in+((DWORD)3 * (DWORD)x)))* FD]; accg += (double)( * (in+((DWORD)3 * (DWORD)x+1))) * FQj; accb += (double)( * (in+((DWORD)3 * (DWORD)x+2)))* Ffj]; } } CurrPI = (DWORD)3 * (DWORD)i ; if (accr < 0.0) *(out+CurrPI) = 0; else if (accr > 255.0) • (out+CurrPI) = 255; else *(out+CurrPI) = (BYTE)(0.5 + accr);; CurrPI = (DWORD)3*(DWORD)i+1 ; if (accg < 0.0) *(out+CurrPI) = 0; else if(accg > 255.0) *(out+CurrPI) = 255; else *(out+CurrPI) = (BYTE)(0.5 + accg); . CurrPI = (DWORD)3 * (DWORD)i+2 ; -7A if(accb < 0.0) *(out+CurrPI) = 0; else if(accb > 255.0) *(out+CurrPI) = 255; else *(out+CurrPI) = (BYTE)(0.5 + accb);; } return 1 ; } int PASCAL edge_refine(MYBITMAP * Bmap,EDGE * e,int Len) { double dx ; double dy ; int status; dx = fabs(e->xe - e->xs); dy = fabs(e->ye - e->ys); if(dx < dy) e->vertical = 1 ; else e->vertical = 0; if(e->vertical) { I* horizontal search for max. gradient 7 ff(status = h_refine(Bmap,&(e->xs), &(e->ys),Len)) retum(status); if(status = h_refine(Bmap,&(e->xe), &(e->ye),Len)) retum(status); } else { /* vertical search for max. gradient 7 if(status = v_refine(Bmap,&(e->xs), &(e->ys),Len)) retum(status); if(status = v_refιne(Bmap,&(e->xe), &(e->ye),Len)) retum(status); } retum(O); 3T3 int PASCAL sub_pixel_interp(double ep, double ec, double en, double *zm, double * em) { /* 1 D sup-pixel estimation of the registration error minimum: * ep = A (-1 ) Λ 2 + B (-1 ) + C = A - B + C * ec = A ( 0) Λ 2 + B ( 0) + C = C * en = A (+1) Λ 2 + B (+1) + C = A + B + C * * yields the following solution: 7 double C = ec; double A = (ep + en) / 2.0 - C; double B = (en - ep) / 2.0; double z; * sup-pixel poistion estimate is zm 7 z = * zm = - (B / (2.0 * A)); //*em = z*(A * z +B) +C ; * em = A * z * z + B * z + C; retum(O); } #define EMAX 10000000L #define RO 14 /* search range 7 #define RY 6 /* Search range in Y direction*/ double Exy[2*RY+1][2*R0+1] ; HFILE hFile ; OFSTRUCT of ; int PASCAL xysolve(HWND hwnd.MYBITMAP * CurrBmap, MYBITMAP • DestBmap, SHIFT *Shifts,TR_WIN * Windows,int WindowsNum, TRACK.POINTS TrBase.TRACK.POINTS TrPoints, 3 q Perspective.Transform * NewTransf, HFILE hFile, TRACK.POINTS * DBasep.RPOINT * DiffArr) { int k, num; SHIFT i; char StringfδO] ; int Wr = 0 ; intj ; double HalfX,HalfY ; SHIFT.POINTS InitPos, NewPos ; RPOINT ShiftValsfNUM.OF.TRACK.POINTS] ; int IndexesfNUM.OF.TRACK.POINTS] ; int Size, Counter ; int Remindex ; for ( k = 0 ; k < NUM_OF_TRACK.POINTS ; k++ ) { Shiftsfkj.dx = Shiftsfkj.dy = Shiftsfkj.sim = 0.0 ; } k = 0 ; Counter = 0 ; for(k = 0 ; k < TrPoints->NumOfPoints; k++) { //for(k = 0 ; k < WindowsNum; k++) { if ( xysrch(hwnd,CurrBmap,DestBmap,&(Shifts[k]), TrBase->TrackPfk],TrPoints->TrackPfk], //(int)(Windows[k].Xdir) I (int)(Windowsfk].Ydir),10,4) != 0 ) { CORR_WINDOWX,CORR_WINDOWY,/*R0,RY710,5) != 0 ) { ShiftValsfCounter].x = Shiftsfkj.dx ; ShiftVals[Counter].y = Shifts[k].dy ; IndexesfCounter] = k ; Counter++ ; } } for ( k = 0 ; k < Counter ; k++ ) { //InitPos.TrackPfkj.x = (double)DBasep->TrackP[lndexesfk]].x ; // Replacing clustering. 3 S TITUTE SHEET (RUl //InitPos.TrackPfkj.y = (double)DBasep->TrackP[lndexes[k]].y ; // Replacing clustering. InitPos.TrackPfkj.x = (double)TrBase->TrackPflndexes[k]].x ; // Replacing clustering. InitPos.TrackPfkj.y = (double)TrBase->TrackP[lndexesfk]].y ; // Replacing clustering. ^ NewPos.TrackPfkj.x = TrPoints->TrackP[lndexesfk]].x + ShiftValsfkj.x - DiffArr[lndexes[k]].x; // Replacing clustering. NewPos.TrackPfkj.y = TrPoints->TrackP[lndexes[k]].y + ShiftVals[k].y -DiffArr[lndexes[k]].y; // Replacing clustering. } Size = Counter ; // Replacing clustering. strcpy(String,"lnitPos After Clustertn") ; // _lwhte(hFile,String,strien(String)) ; // for ( k = 0 ; k < Size ; k++ ) { // sphntf(String,"%lf,%lf\n",lnitPos.TrackP[k].x, InitPos.TrackPfkj.y);// Jwrite(hFile,String,strien(String)) ; // } // strcpy(String,"\n\nNewPos After Cluster\n") ; // _lwrite(hFile,String,strlen(String)) ; // for ( k = 0 ; k < Size ; k++ ) { // sprintf(String,"%lf,%lf\n",NewPos.TrackP[k].x,NewPos.TrackP[k].y); // Jwrite(hFile,String,strlen(String)) ; // } // _lwrite(hFile,"\n\n_n",3) ; // Removing 20 % Of Bad Points /* delete_exterme_point(ln.tPos,NewPos, Size, X.AXIS ,&Remlndex) ; for ( j = Remlndex ; j < Size-1 ; j++ ) { InitPos.TrackPO] = lnitPos.TrackPO+1] ; NewPos.TrackPO] = NewPos.TrackPO+1] ; } Size- ; delete.exterme.point(lnitPos,NewPos, Size, Y.AXIS ,&Remlndex) ; for ( j = Remlndex ; j < Size-1 ; j++ ) { InitPos.TrackPO] = lnitPos.TrackP +1] ; NewPos.TrackPO] = NewPos.TrackP +1] ; } Size- ; 7 if ( get_in_series_flag() == 1 ) { tmSim(lnitPos, NewPos, Size.NewTransf.hFile) ; } else { tmSim(lnitPos, NewPos, Size.NewTransf.hFile) ; //LSE_Perspective(hwnd,lnitPos, NewPos, Size, NewTransf) ; } for ( k = 0 ; k < Size ; k++ ) { • double DstX,DstY,w ; DstX = InitPos.TrackPfkj.x * NewTransf->PffO][0] + InitPos.TrackPfkj.y * NewTransf->Pff 1 jfO] + NewTransf- >PfI2][0] ; DstY = InitPos.TrackPfkj.x * NewTransf->Pf[0]f1] + InitPos.TrackPfkj.y * NewTransf->Pf[1 ][1 ] + NewTransf- >Pf[2][1j ; w = InitPos.TrackPfkj.x * NewTransf->PffO][2] +- InitPos.TrackPfkj.y * NewTransf->Pff1][2] + NewTransf- >Pf[2][2] ; sprintf(Sthng,"%lf->%lf:::%lf->%lf\n",initPos.TrackP[k].x,DstX/w, InitPos.TrackPfkj.y, DstY/w) ; Jwrite(hFile,String,strlen(Sthng)) ; } for ( j = 0 ; j < 3 ; j++ ) { // sprintf(String,"\n%lf, %lf, %lf\n",NewTransf->PfO][0], // NewTransf->Pf ]f1 ], NewTransf->PfO]f2j) ; // Jwrite(hFile,String,strlen(String)) ; // } / retum(1); } int PASCAL xysrch(HWND hwnd.MYBITMAP * CurrBmap,MYB!TMAP • OriginSign, SHIFT *s,POINT pBase.POINT pLast.int CorWinX.int CorWinY.int XWin, int YWin) { int x.O, y_0; int dx, dy, k, I; int x_n,y_n ; int dj, di; double t,r ; int i ; double em; double e ; char StringfδO] ; int long PixInWin ; char Buffer[256] ; long Tresh ; BYTE huge *CurrPtr ; BYTE huge * ZeroPtr ; int FromX,FromY ; double z, d , area; x.O = pBase.x; y.O = pBase.y; FromX = pLasLx ; FromY = pLast.y ; PixInWin = (DWORD)(CorWinX*2+1 ) * (DWORD)(CorWinY * 2+1 ) ; Tresh = (DWORD)12*(DWORD)PixInWin ; //Tresh = (DWORD)4*(DWORD)PixlnWin ; area = (2 * CorWinY + 1 ) * (2 * CorWmX + 1 ); em = 1.0e20; y.n = FromY -YWin -1 ; for(dy = -YWin; dy <= YWin; dy++) { y.n++ ; for(dx = -XWin; dx <= XWin; dx++) { x_n = FromX +dx ; e = 0.0 ; 3'7S for(k = -CorWinY; k <= CorWinY; k++) { CurrPtr = BITMAP_PLACE_PTR(CurrBmap,y_n+k,x_n) ; ZeroPtr = BITMAP_PLACE_PTR(OriginSign,y_0+k,x_0) ; for(l = -CorWinX; I <= CorWinX; I++) { z = CurrPtrfl] - ZeroPtrflj ; e = e + z * z; } } e /= area; Exyfdy+YWinjfdx+XWin] = e; I* update min. error 7 if(e < em) { em = e; dj = dx; di = dy; } } } s->dx = dj ; s->dy = di ; if ( em > Tresh ) return 0 ; if ( abs(dj) == XWin || abs(di) == YWin ) return 0 ; sub_pixel_refine(dj,di,dj+XWin, di+YWin, s); return 1 ; } int PASCAL sub_pixel_refine(int dj, int di, int dxlndex,int dylndex,SHIFT *s) { double deltax, deltay; double simx, simy; s->dx = dj; s->dy = di; s->sim = Exyfdylndex][dxlndex]; 311 sub_pixel_interp(Exy[dylndexJfdxlndex-1], ExyfdylndexJfdxlndexJ, Exy[dylndexJ[dxlndex+1], &deltax, &simx); sub_pixel_interp(Exy[dylndex-1][dxlndex], Exyfdylndexjfdxlndex], Exy[dylndex+1]fdxlndex], &deltay, &simy); s->dx += deltax; s->dy += deltay; s->sim = (simx + simy) / 2.0; return(O); } static double Mpf8]f8], Ap[8]; double Gf2 * NUM.OF.TRACK.POINTSjfδj; double Gt[8]f2 * NUM.OF.TRACK.POINTS]; double Fprf2 * NUM.OF.TRACK.POINTS]; int PASCAL Quad2Quad(HWND hwnd.RPOINT srcpnts[4],RPOINT dstpnts[4j, Perspective.Transform *Tp) { int ij, k, status; double x,y,u,v ; for(k = 0; k < 4; k++) { x = dstpntsfkj.x; y = dstpntsfkj.y; u = srcpntsfkj.x; v = srcpnts[k].y; Apf k] = x; 380 SUBSTITUTE SHEET (RULE 28 Ap[4 + k] = y; xPerspEqn(x, u, v, Mpf k]); yPerspEqn(y, u, v, Mp[4 + kj); } qrsolv8(hwnd, Mp, 8, Ap); Tp->PffO][0] = ApfOj; Tp->Pff1][0] = Ap[1]; Tp->Pff2][0] = Apf2j; Tp->Pf[0][1] = Ap[3]; Tp->Pff1][1] = Ap[4]; Tp->Pff2][1] = Ap[5]; Tp->PffO][2] = Ap[6]; Tp->Pf[1][2] = Ap[7]; Tp->Pff2][2] = 1.0; status = invertPerspective(Tp->Pf, Tp->Pb); retum(1 ); } int PASCAL copy.transform(Perspective.Transform *To,Perspective.Transform * From) { int ij ; for ( i = 0 ; i < 3 ; i++ ) { for ( j = 0 ; j < 3 ; j++ ) { To->Pffi]0] = From->Pffi]ϋl ; To->Pb[i]0] = From->Pb[i]D] ; } } return 1 ; } 2 int PASCAL LSE_Persρective(HWND hwnd.SHIFT.POINTS src_pts, SHIFT.POINTS dstjDts, int pnum, Perspective.Transform *Tp) { int ij, k, status; double x,y,u,v ; if(pnum < 4) { MessageBox (hwnd, "Cannot solve perspective with less than 3 points." , "Shifts", MBJCONEXCLAMATION | MB.OK) ; return 0 ; } if(pnum == 4) { / * Quad2Quad 7 for(k = 0; k < 4; k++) { x = dst_pts.TrackP[k].x; y = dst_pts.TrackP[k].y; u = src_pts.TrackP[k].x; v = src_pts.TrackP[k].y; Apf k] = x; Ap[4 + k] = y; xPerspEqn(x, u, v, Mpf k]); yPerspEqn(y, u, v, Mρ[4 + kj); } } else { for(k = 0; k < pnum; k++) { x = dst_pts.TrackP[k].x; y = dst_pts.TrackP[k].y; u = src_ρts.TrackP[k].x; v = src.pts.TrackP[k].y; Fprf k] = x; Fprfpnum + kj = y; 3S3_ xPerspEqn(x, u, v, Gfkj); yPerspEqn(y, u, v, Gfpnum + kj); } for(k = 0; k < 2 * pnum; k++) { forQ = 0; j < 8; j++) { Gtϋjfk] = Gfkjϋ]; } } for (i = 0; i < 8; i++) { for ϋ = 0; j < 8; j++) { Mpfijϋ] = 0.0; for (k = 0; k < 2 * pnum; k++) { MpfijQ] += Gtfijfk] * GfkJO]; } } } for(j = 0; j < 8; j++) { ApO] = 0; for(k = 0; k < pnum * 2; k++) { ApOl += GtOJfk] * Fprfk]; } } qrsolv8(hwnd, Mp, 8, Ap); Tp->PffO][0] : ApfO] Tp->Pff1]fO] ; Ap[1] Tp->Pf[2]fO] : Apf2j; Tp->PffO]f1] Ap[3]i Tp->Pf[1][1] Ap[4] Tp->Pff2][1] ^ Apf5] Tp->Pf{0][2] Ap[6] Tp->Pff1][2] Ap[7] 2,1 Tp->Pf[2]f2j = 1.0; status = invertPerspective(Tp->Pf, Tp->Pb); return(1 ); int PASCAL xPerspEqn(double x, double u, double v, double *xRow) { xRowfO] = u; xRowfl] = v; xRow[2] = 1 ; xRowf3] = 0; xRow{4] = 0; xRowfδ] = 0; xRow[6] = - u * x; xRowf7] = - v * x; int PASCAL yPerspEqn(double y, double u, double v, double *yRow) { yRowfO] = 0; yRow[1] = 0; yRowf2] = 0; yRow[3j = u; yRowf4] = v; yRowf5j = 1; yRowfβ] = - u * y; yRowf7j = - v * y; int PASCAL qrsolvδ (HWND hwnd, double mfSIZEjfSIZE], int size, double bfSIZE]) { int i, j; 3 4 fit double tau, mlfSIZE], m2[S!ZE]; if (qrdecomp (m, size, ml , m2) < 0) { MessageBox (hwnd, "singularity in qrdecomp()." , "Shifts", MB.ICONEXCLAMATION | MB.OK) ; return 0 ; } for 0 = 0; j < (size - 1); j++) { tau = 0.0; for (i = j; i < size; i++) tau += m[iJO] * b[i]; tau /= m1 j; for (i = j; i < size; i++) bfi] -= tau * mimπ; } bfsize - 1] /= m2[size - 1]; rsolv (m, size, m2, b); } I * * Compute the QR decomposition of a square matrix m using the Stewart * algorithm. Upon termination , thr decomposition is stored in m,m1 and m2 as * follows: * R is contained in the upper triangle of m except that its main * diagonal is contained in m2, and Q(transpos)=Q(n-1) * ...*Q(1) * where Q(j)=l-(Uj*Uj(transpos)/Pj) where Ujfi]=0. i=1->j-1, Ujfi]=m[i]ϋ],i=j->n, Pj=m1Q]. * * Stewart, G.W., Introduction to matrix Computations , Academic Press, New York (1973). * * C Implementaion: Dr. I. Wilf. 7 3S ^ int PASCAL qrdecomp (double mfS!ZE][SIZE], int size, double mlfSIZE], double m2fSIZE]) { int i,kj ; double eta,t,sigma,tau ; for (k = 0; k < (size - 1); k++) { eta = 0.0; for (i = k; i < size; i++) if (fabs (mfijfk]) > eta) eta = fabs (mfi]fkj); if (eta == 0.0) return (-1 ); r form Qk and premultiply m by it 7 t = 0; for (i = k; i < size; i++) { m[i][k] /= eta; t += m[i][k] * mfijfk]; } if(mfk][k] >= 0.0) sigma = sqrt(t); else sigma = -sqrt(t); m[k]fk] += sigma; m1[k] = sigma * m[k][k]; m2[k] = (-eta * sigma); tau = 0; for (j = k + 1 ; j < size; j++) { tau = 0; for (i = k; i < size; i++) tau += mfijfk] * m[i]0]; tau /= m1[k]; for (i = k; i < size; i++) m[i]0] -= tau * mfijfkj; } } m2[size - 1] = mfsize - Ijfsize - 1]; return (0); 3fø rsolv(m,size,m2,b) solve Rx=b for b, where the upper triangular matrix R is stored in M , m2. C Implementaion: Dr. I. Wilf. 7 int PASCAL rsolv (double mfSIZEjfSIZE], int size, double *m2, double *b) { int ij ; double s; for (i = size - 2; i >= 0; i-) { s = 0; for (j = i + 1 ; j < size; j++) s += mfiJO] * bO]; bfi] = (bfi] - s) / m2[i]; } int PASCAL invertPerspective(double Pf[3][3], double Pbf3][3]) { double a11 ■ ■ Pf[0][0] double a12 ■ Pff0][1]i double a13 ■■ Pff0]f2] double a21 Pff1][0]: double a22 Pf[1][1] double a23 Pff1]f2] double a31 : P f2][0] double a32 ■ Pff2][1]; double a33 ■ Pf[2j[2] PbfOjfO] = a22 * a33 - a23 * a32; Pbf0][1] = a13 * a32 - a12 * a33 Pb[0]f2] = a12 * a23 - a13 * a22 331 TITUTE SHEET (RULE 26^ Pb[1][0] = a23 * a31 - a21 * a33 Pb[1][1J = a11 *a33-a13 * a31 Pb[1]f2j = a13 * a21 -a11 * a23 Pb[2][0] = a21 * a32 - a22 * a31 Pb[2][1] = a12*a31 -a11 * a32 Pb[2][2] = a11 *a22-a12 * a21 inv3(Pf, Pb); retum(O); } int PASCAL inv3(double y[3][3], double zf3][3j) { double b[2][2],dety,detb; int ij,k,l,k1,H; dety=det3(y); if(dety==0.0) retum(1); /* compute f] .7 for(i=0;i< 3;i++) for(j=0;j< 3;j++) { for(k = 0; k < 2; k++) for(l = 0; l< 2; I++) { if(l<i) 11=1; else 11=1+1; if(k<j) k1=k; else k1=k+1; b[k][l]=y[k1][H]; } detb=b[0][0]*b[1 ][1 ]-b[1 ][0] * bf0][1 ]; if(((i+j)%2)==O)zfi]0]=detb/dety; else z[i]0 ' ]=(-detb)/dety; } } double PASCAL det3(double y[3][3]) 3*3 { short j,k,l; double b[2]f2],det,detb; det=0.0; forG=0;j<=2;j++) { for(k=0;k<=1;k++) for(l=0;K=1;l++) { if(l<j) b[k][l]=y[k+1][lj; else bfk][l]=y[k+1][l+1]; } detb=b[0][0j * b[1 ][1 ]-b[0]f 1 ] * b[1 ][0j; if(0%2)==O) det=det+y[0]ϋ] * detb; else det=det-yfO]0] * detb; } retum(det); } /* int PASCAL invertPerspectiye(double Pff3][3], double Pb[3]f3]) { double a11,a12,a13,a21,a22,a23,a31,a32,a33 ; a11 = Pff0][0j; a12 = PffO][1]; a13 = PffO][2]; a21 = Pf[1]f0]; a22 = Pff1][1]; a23 = Pff1]f2]; a31 = Pff2][0j; a32 = Pf[2]f1]; a33 = Pff2][2j; PbfOjfO] = a22 * a33 - a23 * a32 Pbf0]f1] = a13 * a32 - a12 * a33 Pbf0]f2] = a12 * a23 - a13 * a22: 3^1 Pb[1]fOj = a23 * a31 - a21 * a33 Pbf1][1] = a11 *a33-a13 * a31 Pb[1]f2] = a13*a21 -a11 * a23 Pb[2jf0] = a21 * a32 - a22 * a31 Pb[2]f1] = a12 * a31 -a11 *a32 Pb[2][2] = a11 *a22-a12 * a21 retum(O); } 7 int PASCAL h_refιne(MYBlTMAP *Bmap, double *x, double *y.int Len) { int i, j, k, km; int z = Len + 1 ; double u, gm; double gmax; double a, b, c, d, e, f; double Rx, Gx, Bx; int rows.cols ; DWORD Size ; int EfectLen ; double *Gh ; i = (int)( * y + 0.5); j = (int)(*x + 0.5); cols = Bmap->cols ; rows = Bmap->rows ; ifO < z || j > (cols - z)) return(1 ); if(i < 1 || i > (rows - 2)) return(1 ); EfectLen = (DWORD)Len*(DWORD)2+1 ; Size = (DWORD)(sizeof(double))*(DWORD)Len*(DWORD)2+2 ; Gh = (double *)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; for(k = -Len; k <= Len; k++) { a = *(BITMAP_RGB.PLACE_PTR(Bmap,i-1j+k-1)) ; 3^0 b = * (BITMAP_RGB_PLACE_PTR(Bmap,i,j+k-1)) ; c = * (BITMAP_RGB_PLACE_PTR(Bmap,i+1,j+k-1)) ; d = * (BITMAP_RGB_PLACE_PTR(Bmap,i-1,j+k)) ; e = * (BITMAP_RGB_PLACE_PTR(Bmap,ij+k)) ; f = *(BITMAP_RGB_PLACE_PTR(Bmap,i+1,j+k)) ; Rx = a + 2.0*b + c-d-2.0 * e-f; a = * (BITMAP.RGB_PLACE_PTR(Bmap,i-1,j+k-1)+1) ; b = *(BITMAP_RGB.PLACE_PTR(Bmap,ij+k-1)+1) ; c = * (BITMAP_RGB.PLACE_PTR(Bmap,i+1,j+k-1)+1) ; d = * (BITMAP_RGB_PLACE_PTR(Bmap,i-1 +k)+1) ; e = *(BITMAP_RGB_PLACE_PTR(Bmap,ij+k)+1) ; f = *(BITMAP_RGB_PLACE_PTR(Bmap,i+1 j+k)+1) ; Gx = a + 2.0 * b + c-d-2.0 * e-f; a = * (BITMAP_RGB_PLACE_PTR(Bmap,i-1 +k-1)+2) ; b = * (BITMAP_RGB_PLACE.PTR(Bmap,ij+k-1)+2) ; c = * (B!TMAP_RGB_PLACE_PTR(Bmap,i+1j+k-1)+2) ; d = * (BITMAP_RGB_PLACE.PTR(Bmap,i-1,j+k)+2) ; e = * (B!TMAP_RGB_PLACE.PTR(Bmap,ij+k)+2) ; f = * (BITMAP_RGB_PLACE_PTR(Bmap,i+1 j+k)+2) ; Bx = a + 2.0 * b + c-d-2.0*e-f; Ghfk+Len] = sqrt(Rx * Rx + Gx * Gx + Bx * Bx); } /* Find maximal response 7 km = 0; gm = GhfO]; for(k = 1 ; k < EfectLen; k++) { if(Gh[k] > gm) { km = k; gm = Ghfk]; } } if(km == 0 || km == EfectLen) { 3 c ιι RULE ^ GlobalFreePtr(Gh) ; return(1 ); } sub_ρixel.interp(Gh[km-1], Ghfkm], Gh[km+1], &u, &gmax); /* can threshold gmax to decide if edge detection was successful 7 GlobalFreePtr(Gh) ; if ( gmax < 100.0 ) retum(1 ) ; *x += u+km; return(O); int PASCAL v.refine(MYBITMAP * Bmap,double *x, double *y,int Len) { int i, j, k, km; int z = Len + 1 ; double v, gm; double gmax; int cols, rows ; DWORD Size ; int EfectLen ; double a, b, c, d, e, f; double Ry, Gy, By; double * Gh ; i = (int)( * y + 0.5); j = (int)( * x + 0.5); cols = Bmap->cols ; rows = Bmap->rows ; i G z II j (cols - z)) retum(1 ); if(i < 1 || i > (rows - 2)) return(1); EfectLen = (DWORD)Len*(DWORD)2+1 ; Size = (DWORD)(sizeof(double))*(DWORD)Len*(DWORD)2+2 ; Gh = (double *)GlobalAllocPtr(GMEM_MOVEABLE,Size) ; for(k = -Len; k <= Len; k++) { a = *(BITMAP.RGB_PLACE_PTR(Bmap,i+k-1j-1)) ; 3% b = *(BITMAP_RGB_PLACE_PTR(Bmap,i+k-1 j)) ; c = *(BlTMAP_RGB_PLACE_PTR(Bmap,i+k-1 ,j+1)) ; d = *(BITMAP_RGB_PLACE_PTR(Bmap,i+k,j-1)) ; e = *(BITMAP_RGB_PLACE_PTR(Bmap,i+kj)) ; f = *(BITMAP.RGB_PLACE_PTR(Bmap,i+kj+1)) ; Ry = a + 2.0 * b + c - d - 2.0 * e - f; a = * (BITMAP_RGB_PLACE_PTR(Bmap,i+k-1j-1)+1) ; b = *(BITMAP_RGB_PLACE_PTR(Bmap,i+k-1 j)+1) ; c = *(BITMAP_RGB_PLACE_PTR(Bmap,i+k-1,j+1)+1) ; d = *(BITMAP_RGB_PLACE_PTR(Bmap,i+kj-1)+1) ; e = * (BITMAP_RGB_PLACE_PTR(Bmap,i+kj)+1 ) ; f = * (BITMAP.RGB_PLACE_PTR(Bmap,i+kj+1)+1) ; Gy = a + 2.0 * b + c - d - 2.0 * e - f; a = *(BITMAP_RGB_PLACE_PTR(Bmap,i+k-1j-1)+2) ; b = *(BITMAP_RGB.PLACE.PTR(Bmap.i+k-1j)+2) ; c = * (BITMAP_RGB_PLACE_PTR(Bmap,i+k- : l j+1)+2) ; d = *(BITMAP_RGB_PLACE_PTR(Bmap,i+kj-1)+2) ; e = *(BITMAP_RGB_PLACE_PTR(Bmap,i+kj)+2) ; f = *(BITMAP_RGB.PLACE_PTR(Bmap,i+kj+1)+2) ; By = a + 2.0 * b + c - d - 2.0 * e - f; Ghfk+Len] = sqrt(Ry * Ry + Gy * Gy + By * By); } /* Find maximal response 7 km = 0; gm = GhfO]; for(k = 1; k < EfectLen; k++) { if(Gh[k] > gm) { km = k; gm = Ghfk]; } } jf(km == 0 || km == EfectLen) { GlobalFreePtr(Gh) ; <β retum(1); } sub_pixel_interp(Gh[km-1], Ghfkm], Gh[km+1], &v, &gmax); /* can threshold gmax to decide if edge detection was successful 7 GlobalFreePtr(Gh) ; if ( gmax < 100.0 ) retum(1 ) ; *y += v+km; return(O); .} #defιne ORDER 8 #define NDATA 20 static double qrMfORDERjfORDER], qrAfORDERj; double qrG[2 * NDATA][ORDER]; double qrGt[ORDER]f2 * NDATA]; double qrFf . 2 * NDATA]; int PASCAL Thin.Perspective(HWND hwnd, SHIFT.POINTS src_pts, SHIFT.POINTS dst_pts, int pnum, Perspective.Transform *Tp) { int i, j, k, status; if(pnum < 3) { MessageBox (hwnd, "Cannot solve perspective with less than 3 points." , "Shifts", MB.ICONEXCLAMATION | MB.OK) ; return 0 ; } for(k = 0; k < pnum; k++) { double x = dst_pts.TrackPfk].x; double y = dst_pts.TrackP[k].y; double u = src_pts.TrackPfk].x; double v = src_pts.TrackP[k].y; qrFf k] = x; 3 f ι < f qrFfpnum + k] = y; xThinEqn(x, u, v, qrGf k]); yThinEqn(y, u, v, qrGfpnum + kj); continue; } fόr(k = 0; k < 2 * pnum; k++) { for(j = 0; j < 5; j++) { qrGtO][k] = qrGfkJO]; } } for(i = 0; i < 5; i++) for(j = 0; j < 5; j++) { qrM[i]ϋ] = 0.0; for(k = 0; k < 2 * pnum; k++) { qrMfi]DJ += qrGt[i]fk] * qrG[k]DJ; } } forϋ = 0; j < 5; j++) { qrAfj] = 0; for(k = 0; k < pnum * 2; k++) { qrAO] += qrGtO][k] * qrF[k]; } } qrsolv(qrM, 5, qrA); Tp->PffO][0] = qrAfOj; Tp->Pff1][0] = qrA[1]; Tp->Pff2][0] = qrAf2]; Tp->Pf[0][1] = -qrA[1]; Tp->Pff1]f1] = qrAfOj; Tp->Pff2][1] = qrAf3]; Tp->PffO][2] = qrA[4]; Tp->Pf[1]f2] = 0.0; Tp->Pf[2][2] = 1.0; status = invertPerspective(Tp->Pf, Tp->Pb); return(1); } int PASCAL xThinEqn(double x, double u, double v, double *xRow) { xRowfO] = u; xRowfl] = v; xRowf2] = 1 ; xRowf3] = 0; xRow[4] = - u * x; return 1 ; } int PASCAL yThinEqn(double y, double u, double v, double *yRow) { yRowfO] = v; yRowfl] = -u; yRowf2] = 0; yRowf3] s 1 ; yRowf4] = - u * y; return 1 ; } int PASCAL trans.grey_frame.to.fields(HWND hwnd, RPOINT • SrcPnts.RPOINT *DstPnts, MYBITMAP *SrcBmap, RPOINT * FrPnts, MYBITMAP ** F1, MYBITMAP * * F2) { Perspective.Transform TpCurr.BasicTransf ; RPOINT FrDst[4],CrnPoly[4] ; RECT Rectan ; MYBITMAP *DestBmap ; DWORD Size ; int Cols.Rows ; 3% Quad2Quad(hwnd,FrPnts,DstPnts,&TpCurr) ; l_find.bound.rect(DstPnts, &Rectan) ; l_quad_in_new_origin(CmPoly, DstPnts, Rectan. left, Rectan.top, 4) ; Cols = Rectan. right-Rectan.left+1 ; Rows = Rectan.bottom-Rectan.top+1 ; *F1 = bm_alloc(Cols,Rows,GREY.MODEL) ; Size = (DWORD)Cols * (DWORD)Rows ; (*F1)->gpic = (BYTE huge * )GlobalAllocPtr(GMEM_MOVEABLE,Size) ; perspective(hwnd,SrcBmap,*F1 ,FrPnts, CmPoly, GREY.MODEL, &BasicTransf) ; //split.bitmap_frame(SrcBmap,F1, F2) ; //bm.free(DestBmap) ; return 1 ; } #define NZOOM 256 #define WNUM 32 double rZoomsfNZOOMj; double rThetafNZOOMj; double rDxfWNUM]; double rDyfWNUM]; double ValArrf] = {0.0, 0.0, 0.0, 0.0} ; double Wheightf] = {2.0,2.0,3.0,3.0} ; int PASCAL tmSim(SHIFT.POINTS mpts, SHIFT.POINTS fpts, int pnum, Perspective.Transform *Tp, HFILE hFile) { double zoom, theta; double zsin, zcos; char String[50] ; double dx, dy; double Orgtheta ; int i, j, nZoom = 0; double mien, flen ; σ n double mtheta, ftheta ; if(pnum > WNUM) pnum = WNUM; for(i = 0; i < pnum; i++) for(j = i + 1 ; j < pnum; j++) { mien = norm2(mpts.TrackP[i], mpts.TrackPO]); if(mlen < 30.0) continue; flen = norm2(fpts.TrackP[i], fpts.TrackPO ' ]); mtheta = atan2(mpts.TrackP0].x - mpts.TraekPfij.x, mpts.TrackPOJ.y - mpts.TrackPfij.y); ftheta = atan2(fpts.TrackP0].x - fpts.TrackP[i].x, fpts.TrackPOJ.y - fpts.TrackPfij.y); zoom = flen / mien; theta = ftheta - mtheta; if(nZoom < NZOOM) { rZoomsfnZoom] = zoom; rThetafnZoom] = theta; ++nZoom; } } { /* Trimmed-mean estimate of theta 7 double tavg = 0.0; int q1 = nZoom / 4; int q3 = 3 * q1 ; qsort((void*)rTheta, (size.t)nZoom, sizeof(double), dcomp); for(i = q1; i < q3; i++) tavg += rThetafi]; tavg /= (double)(q3 - q1); 3 theta = tavg; } { /* Trimmed-mean estimate of zoom 7 double zavg = 0.0; int q1 = nZoom / 4; int q3 = 3 * q1 ; qsort((void * ) rZooms, (size.t) nZoom, sizeof(double), dcomp); for(i = q1 ; i < q3; i++) zavg += rZoomsfi]; zavg /= (double)(q3 - q1 ); zoom = zavg; } //Orgtheta = theta ; //smooth_values(Orgtheta, &theta,ValArr,4,Wheight) ; sprintf(String n%ZOOM %lf, THETA %lf\n",zoom,theta) ; // _lwrite(hFiie,String,strlen(Sthng)) ; zcos = zoom * cos(theta); zsin = zoom * sin(theta); for(i = 0; i < pnum; i++) { . rDxfi] = fpts.TrackPfij.x - zcos * mpts.TraekPfij.x - zsin * mpts.TrackPfij.y; rDyfi] = fpts.TrackPfij.y + zsin * mpts.TraekPfij.x - zcos * mpts.TrackPfij.y; } { / * Trimmed-mean estimate of dx 7 double xavg = 0.0; int q1 = pnum / 4; int q3 = 3 * q1; qsort((void*)rDx, (size.t)pnum, sizeof(double), dcomp); for(i = q1; i < q3; i++) xavg += rDxfi]; xavg /= (double)(q3 - q1); dx = xavg; 3 \ } { /* Trimmed-mean estimate of dy 7 double yavg = 0.0; int q1 = pnum / 4; int q3 = 3 * q1 ; qsort((void * )rDy, (size.t)pnum, sizeof(double), dcomp); for(i = q1 ; i < q3; i++) yavg += rDyfij; yavg /= (double)(q3 - q1 ); dy = yavg; } { /* Fill fwd. matrix 7 Tp->Pff0][0] = zcos; Tp->Pff1][0] = zsin; Tp->Pf[2]f0] = dx; Tp->Pff0][1] = -zsin; Tp->Pf[1][1] = zcos; Tp->Pff2][1] = dy; Tp->Pff0][2] = 0; Tp->Pff1][2] = 0 Tp->Pf[2]f2] = 1 inv3(Tp->Pf, Tp->Pb); } retum(1); } double norm2(RPOINT a, RPOINT b) { double dx - a.x - b.x; double dy = a.y - b.y; return(sqrt(dx * dx + dy * dy)); } int cdecl dcomp(const void * a, const void * b)/ * (double * a, double * b)7 { if(*(double * )a == *(double * )b) retum(O); retum(*(double * )a < *(double * )b ? -1 : 1); } int PASCAL delete_exterme_point(SHIFT_POINTS init,SHIFT_POINTS new, int Size, int Axis.int * lndex) { int i ; double Value.Tmp ; if (Axis = X.AXIS ) { Value = -100.0 ; for ( i = 0 ; i < Size ; i++ ) { if ( (Tmp = fabs(new.TrackP[i].x - iniLTrackPfij.x)) > Value ) { Value = Tmp ; • Index = " i ; } > } if (Axis = Y.AXIS ) { Value = -100.0 ; for ( i = 0 ; i < Size ; i++ ) { if ( (Tmp = fabs(new.TrackP[i].y - iniLTrackPfij.y)) > Value ) { Value = Tmp ; • Index = i ; } } } return 1 ; }

Claims: C A I M S 1. Apparatus for advertisement site detection comprising : a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility; and an advertisement site detector operative to detect at least one advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. 2. Apparatus for advertisement incorporation comprising: a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility; and an advertisement incorporator operative to incorporate a portion of an advertisement into at least one fieϊd at a partially occluded advertisement site within the sports facility, wherein the portion of the incorporated advertisement corresponds to an unoccluded portion of the advertisement site. 3. Apparatus according to claim 2 wherein said advertisement incorporator includes an advertisement site detector operative to detect at least one advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. 4. Apparatus for advertisement site detection comprising: a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility; ψua an advertisement site detector operative to detect at least one advertisement site in at least one field; and an advertisement site tracker operative to track at least one advertisement site detected by the advertisement site detector without tracking an entire field. 5. Apparatus according to claim 2 wherein said advertisement incorporator includes: an advertisement site detector operative to detect at least one advertisement site in at least one field; and an advertisement site tracker operative to track at least one advertisement site detected by the advertisement site detector without tracking an entire field. 6. Apparatus according to claim 4 or claim 5 wherein said advertisement site detector is operative to detect at least one advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. 7. A method for broadcasting advertisements comprising: broadcasting an image of an event including at least one advertisement image; identifying the advertisement image within the image of the event and enhancing only the advertisement image. 8. A method according to claim 7 wherein the step of enhancing comprises the step of sharpening the edges of the advertisement image. 9. A video processing method comprising: detecting a moving object in a video sequence including a plurality of video frames; and attaching an advertisement to the moving object in each of the plurality of the video frames. 10. Apparatus for advertisement image detection comprising: a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility; an advertisement image detector operative to detect at least one advertisement image in at least one field; and an advertisement exposure time counter operative to count the length of the exposure time period of each advertisement image. 11. Apparatus according to claim 10 wherein said time counter is also operative to store at least one characteristic of the exposure time period of each advertisement image other than its length, the apparatus also comprising an advertisement fee computer operative to compute an advertisement fee according to the length of the exposure time period and at least one other characteristic of the exposure time period. 12. Apparatus according to claim 11 wherein the characteristic of the exposure time period other than the length thereof includes an indication of whether or not the exposure time period took place during overtime. 13. Apparatus according to claim 11 wherein the characteristic of the exposure time period other than the length thereof includes an indication of the interval between each. exposure and the. beginning of the game. 14. Apparatus according to claim 11 wherein the characteristic of the exposure time period other than the length thereof includes an indication of temporal proximity to a significant event. 15. Apparatus for incorporation of an audio advertisement into an audio channel representing a sports event, the apparatus comprising: an audio advertisement memory operative to store an audio advertisement; and an audio mixer operative to mix the audio advertisement into an audio channel representing the sports event. 16. Apparatus according to claim 15 and also comprising: a field grabber operative to grab and digitize at least one field representing at least a portion " ' of the sports facility at which the sports event is taking place; and a visual cue detector operative to detect a visual cue in at least one field and to control operation of the audio mixer in accordance with the visual cue. 17. Apparatus according to claim 16 wherein the visual cue comprises an advertisement image corresponding to the audio advertisement. 18. Apparatus for advertisement site detection comprising: an advertisement image memory storing an image of an advertisement to be replaced; a field grabber operative to grab and digitize at least one field representing at least a portion of a sports facility; and a field-memory matcher operative to match at least a portion of a field to at least a portion of the stored image of the advertisement to be replaced, thereby to identify an image of at least a portion of the advertisement to be replaced within the field. 19. Apparatus according to claim 18 and also comprising an advertisement site detector operative to identify at least one edge of at least one advertisement site in at least one field. 20. A broadcasting method comprising: imaging an event using a plurality of TV cameras; and broadcasting the images generated by the plurality of TV cameras. 21. A method according to claim 20 and wherein the step of broadcasting also comprises, for each frame, the step of compressing the images generated by all but ' one of the cameras and mixing the compressed images onto the signal representing the image generated by the single remaining camera. 22. A method according to claim 20 or claim 21 and also comprising the step of receiving the broadcast at a remote location and deriving therefrom information regarding at least one advertisement displayed at the event. 23. A method for advertisement site detection comprising: grabbing and digitizing at least one field representing at least a portion of a sports facility; and detecting at least one advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. 24. A method for advertisement incorporation comprising: grabbing and digitizing at least one field representing at least a portion of a sports facility; and incorporating a portion of an advertisement into at least one field at a partially occluded advertisement site within the sports facility, wherein the portion of the incorporated advertisement corresponds to an unoccluded portion of the adver- tiseraent site. 25. A method for advertisement site detection comprising: grabbing and digitizing at least one field representing at least a portion of a sports facility; detecting at least one advertisement site in at least " one field; and tracking at least one advertisement site detected by the advertisement site detector without tracking an entire field. 26. A method according to claim 22 wherein the information regarding the advertisement includes information pertaining to occlusion of the advertiseraent. 27. A method for advertisement image detection comprising: grabbing and digitizing at least one field representing at least a portion of a sports facility; detecting at least one advertisement image in at least one field; and counting the length of the exposure time period of each advertisement image. 28. A method for incorporation of an audio advertisement into an audio channel representing a sports event, the apparatus comprising: storing an audio advertisement; and mixing the audio advertisement into an audio channel representing the sports event. 29. A method for advertisement site detection comprising: storing an image of an advertisement to be replaced; grabbing and digitizing at least one field representing at least a portion of a sports facility; and matching at least a portion of a field to the stored image of the advertisement to be replaced, thereby to identify an image of the advertisement to be replaced within the field. 30. Apparatus according to claim 1 wherein the advertisement site detector is operative to detect at least one partially occluded advertisement site in at least one field on a basis other than location of the advertisement site relative to the sports facility. 31. Apparatus according to claim 4 wherein the advertisement site tracker is operative to track at least one partially occluded advertisement site detected by the advertisement site detector without tracking an entire field. 32. Apparatus according to claim 18 wherein the advertisement is partially occluded within the field and wherein the field-memory matcher is operative to match only a portion of a field to only a portion of the stored image of the advertisement to be replaced, thereby to identify an image of only a portion of the advertisement to be replaced within the field. 33. A TV camera array monitoring system for monitoring a TV camera array comprising at least one TV camera generating images to be broadcasted, the system comprising: for each TV camera, a camera FOV center direction measurement unit; for each TV camera, a lens zoom state monitoring unit; and a video mixer operative to mix the outputs of the FOV direction measurement and lens zoom state monitoring units onto a signal to be broadcasted. 34. A system according to claim 33 wherein the array comprises a plurality of TV cameras and also comprising an on-air camera identification unit operative to identify the TV camera from among the plurality of TV cameras which is currently on-air. 35. A system according to claim 33 or claim 34 and also comprising a remote advertisement detector operative to receive the broadcast signal and to extract the output of the video mixer therefrom.

Inventors: SHARIR AVI, TAMIR MICHAEL, SHARIR, AVI, TAMIR, MICHAEL
Applicants: ORAD INC, SHARIR AVI, TAMIR MICHAEL, ORAD, INC., SHARIR, AVI, TAMIR, MICHAEL
Application year: 1994
Main classification: H04N7
IPC codes: G01S3, G06T15, H04H1, H04H60, H04N5, H04N7